Skip to content
Permalink
Browse files

Added inventory management

  • Loading branch information...
Lukman Bello
Lukman Bello committed Jun 13, 2019
1 parent 42fa86b commit 50d7b22092bfa0a3f68dac31b5a8cb133cea9b0a
@@ -479,7 +479,7 @@ function kkd_pff_paystack_editor_add_recur_data()
$recur = get_post_meta($post->ID, '_recur', true);
$recurplan = get_post_meta($post->ID, '_recurplan', true);
if ($recur == "") {
if ($recur == "") {
$recur = 'no';
}
if ($recurplan == "") {
@@ -506,16 +506,29 @@ function kkd_pff_paystack_editor_add_quantity_data()
// Get the location data if its already been entered
$usequantity = get_post_meta($post->ID, '_usequantity', true);
$useinventory = get_post_meta($post->ID, '_useinventory', true);
$inventory = get_post_meta($post->ID, '_inventory',true);
$sold = get_post_meta($post->ID, '_sold',true);
$quantity = get_post_meta($post->ID, '_quantity', true);
$quantityunit = get_post_meta($post->ID, '_quantityunit', true);
$recur = get_post_meta($post->ID, '_recur', true);
if ($usequantity == "") {
$usequantity = 'no';
}
if($useinventory == ""){
$useinventory = "no";
}
if ($quantity == "") {
$quantity = '10';
}
if ($inventory == "" ) {
$inventory = '1';
}
if($sold == ""){
$sold = '0';
}
$stock = $inventory - $sold;
if ($quantityunit == "") {
$quantityunit = 'Quantity';
}
@@ -532,8 +545,28 @@ function kkd_pff_paystack_editor_add_quantity_data()
<option value="yes" '.kkd_pff_paystack_txncheck('yes', $usequantity).'>Yes</option>
</select>';
}
if($usequantity == "yes"){
echo '<p>Inventory Payment:</p><small>Set maximum available items in stock</small>';
echo '
<select class="form-control" name="_useinventory" style="width:100%;">
<option value="no" '.kkd_pff_paystack_txncheck('no', $useinventory).'>No</option>
<option value="yes" '.kkd_pff_paystack_txncheck('yes', $useinventory).'>Yes</option>
</select>';
}
if($useinventory == "yes"){
echo '<p>Total Inventory</p>';
echo '<input type="number" min="'.$sold.'" name="_inventory" value="' . $inventory . '" class="widefat pf-number" />';
echo '<p>In stock</p>';
echo '<input type="number" readonly name="_in_stock" value="' . $stock . '" class="widefat pf-number" />
<small></small>';
}
echo '<p>Max payable quantity:</p>';
echo '<input type="number" name="_quantity" value="' . $quantity . '" class="widefat pf-number" />
echo '<input type="number" min="1" name="_quantity" value="' . $quantity . '" class="widefat pf-number" />
<small>Your users only get to pay in quantities if the from amount is not set to zero and recur is set to none.</small>';
echo '<p>Unit of quantity:</p>';
echo '<input type="text" name="_quantityunit" value="' . $quantityunit . '" class="widefat" />
@@ -641,7 +674,8 @@ function kkd_pff_paystack_save_data($post_id, $post)
if (!current_user_can('edit_post', $post->ID)) {
return $post->ID;
}
$form_meta['_inventory'] = $_POST['_inventory'];
$form_meta['_useinventory'] = $_POST['_useinventory'];
$form_meta['_amount'] = $_POST['_amount'];
$form_meta['_hidetitle'] = $_POST['_hidetitle'];
$form_meta['_minimum'] = $_POST['_minimum'];
@@ -22,7 +22,7 @@ public static function activate()
txn_code varchar(255) DEFAULT '' NOT NULL,
txn_code_2 varchar(255) DEFAULT '' NOT NULL,
amount varchar(255) DEFAULT '' NOT NULL,
ip varchar(255) NOT NULL,
ip varchar(255) NOT NULL,
deleted_at varchar(255) DEFAULT '' NULL,
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
modified timestamp DEFAULT '0000-00-00 00:00:00' NOT NULL,
@@ -820,7 +820,24 @@ function kkd_pff_paystack_form_shortcode($atts)
}
}
}
if ((($user_id != 0) && ($loggedin == 'yes')) || $loggedin == 'no') {
$useinventory = get_post_meta($id, '_useinventory', true);
$inventory = get_post_meta($id, '_inventory',true);
$sold = get_post_meta($id, '_sold',true);
if ($inventory == "" ) {
$inventory = '1';
}
if($sold == ""){
$sold = '0';
}
if($useinventory == ""){
$useinventory = "no";
}
$stock = $inventory - $sold;
if($useinventory == "yes" && $stock <= 0){
echo "<h1>Out of Stock</h1>";
}
else if ((($user_id != 0) && ($loggedin == 'yes')) || $loggedin == 'no') {
echo '<div id="paystack-form">';
if ($hidetitle != 1) {
echo "<h1 id='pf-form".$id."'>".$obj->post_title."</h1>";
@@ -902,7 +919,10 @@ function kkd_pff_paystack_form_shortcode($atts)
<input type="hidden" id="pf-vname" name="pf-vname" />
<input type="hidden" id="pf-amount" />
<select class="form-control" id="pf-vamount" name="pf-amount">';
$max = $quantity+1;
$max = $quantity + 1;
if($max > ($stock +1)){
$max = $stock + 1 ;
}
foreach ($paymentoptions as $key => $paymentoption) {
list($a, $b) = explode(':', $paymentoption);
echo '<option value="'.$b.'" data-name="'.$a.'">'.$a.' - '.$currency.' '.number_format($b).'</option>';
@@ -926,7 +946,10 @@ function kkd_pff_paystack_form_shortcode($atts)
<div class="select">
<input type="hidden" value="'.$amount.'" id="pf-qamount"/>
<select class="form-control" id="pf-quantity" name="pf-quantity" >';
$max = $quantity+1;
$max = $quantity + 1;
if($max > ($stock +1)){
$max = $stock + 1 ;
}
for ($i=1; $i < $max; $i++) {
echo ' <option value="'.$i.'">'.$i.'</option>';
}
@@ -1371,7 +1394,12 @@ function kkd_pff_paystack_submit_action()
$txnbearer = get_post_meta($_POST["pf-id"], '_txnbearer', true);
$transaction_charge = get_post_meta($_POST["pf-id"], '_merchantamount', true);
$transaction_charge = $transaction_charge*100;
//--------------------------------------------------------------------------
$sold = get_post_meta($_POST["pf-id"], '_sold', true);
if($sold == ''){
$sold = '0';
}
//--------------------------------------------------------------------------
$txncharge = get_post_meta($_POST["pf-id"], '_txncharge', true);
$minimum = get_post_meta($_POST["pf-id"], '_minimum', true);
$variableamount = get_post_meta($_POST["pf-id"], '_variableamount', true);
@@ -1414,9 +1442,17 @@ function kkd_pff_paystack_submit_action()
$unitamount = (int)str_replace(' ', '', $amount);
$amount = $quantity*$unitamount;
}
//--------------------------------------
$sold = $sold+$quantity;
if (get_post_meta($_POST["pf-id"], '_sold', false)) { // If the custom field already has a value
update_post_meta($_POST["pf-id"], '_sold', $sold);
} else { // If the custom field doesn't have a value
add_post_meta($_POST["pf-id"], '_sold', $sold);
}
//--------------------------------------
if ($txncharge == 'customer') {
$amount = kkd_pff_paystack_add_paystack_charge($amount);
}
@@ -1532,7 +1568,7 @@ function kkd_pff_paystack_submit_action()
$fixedmetadata = json_decode(json_encode($fixedmetadata, JSON_NUMERIC_CHECK), true);
$fixedmetadata = array_merge($untouchedmetadata, $fixedmetadata);
$insert = array(
'post_id' => strip_tags($_POST["pf-id"], ""),
'email' => strip_tags($_POST["pf-pemail"], ""),
@@ -1590,6 +1626,10 @@ function kkd_pff_paystack_submit_action()
'txnbearer' => $txnbearer,
'transaction_charge' => $transaction_charge
);
//-------------------------------------------------------------------------------------------
echo json_encode($response);
die();
}
@@ -9,6 +9,40 @@
width:300px !important;
height:87px !important;
}
@font-face {
font-family: 'Graphik';
font-style: normal;
font-weight: normal;
src: url('/fonts/graphik/Graphik-Regular.eot');
src: url('/fonts/graphik/Graphik-Regular.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('/fonts/graphik/Graphik-Regular.woff') format('woff'), /* Modern Browsers */ url('/fonts/graphik/Graphik-Regular.ttf') format('truetype'), /* Safari, Android, iOS */ url('/fonts/graphik/Graphik-Regular.svg#Graphik-Regular') format('svg');
text-rendering: optimizeLegibility;

/* IE9 Compat Modes */
/* Legacy iOS */
}
@font-face {
font-family: 'Graphik';
font-style: normal;
font-weight: 300;
src: url('/fonts/graphik/Graphik-Light.eot');
src: url('/fonts/graphik/Graphik-Light.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('/fonts/graphik/Graphik-Light.woff') format('woff'), Modern Browsers url('/fonts/graphik/Graphik-Light.ttf') format('truetype'), /* Safari, Android, iOS */ url('/fonts/graphik/Graphik-Light.svg#Graphik-Light') format('svg');
text-rendering: optimizeLegibility;

/* IE9 Compat Modes */
/* Legacy iOS */
}
@font-face {
font-family: 'Graphik';
font-style: normal;
font-weight: bold;
src: url('/fonts/graphik/Graphik-Medium.eot');
src: url('/fonts/graphik/Graphik-Medium.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('/fonts/graphik/Graphik-Medium.woff') format('woff'), /* Modern Browsers */ url('/fonts/graphik/Graphik-Medium.ttf') format('truetype'), /* Safari, Android, iOS */ url('/fonts/graphik/Graphik-Medium.svg#Graphik-Medium') format('svg');
text-rendering: optimizeLegibility;

/* IE9 Compat Modes */
/* Legacy iOS */
}


/* Default
=============================== */
@@ -27,6 +61,11 @@
padding:40px 15px;
max-width: 1280px;
margin: 0 auto;
font-family: 'Graphik', 'Helvetica Neue', 'Arial', sans-serif;
-webkit-text-size-adjust: 100%;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-rendering: optimizeLegibility;
}

#pf-form.j-forms {
@@ -84,6 +123,18 @@
border-radius:0px;
}

.j-forms input{
display: block;
height: 35px;
font-size: 14px;
width: 100%;
line-height: 35px;
padding: 0 10px;
border: solid 1px #cccccc;
border-radius: 2px;
outline: none;
}

/* Header
=============================== */
.j-forms .header {
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -385,6 +385,7 @@ function KkdPffPaystackFee() {
var quantity = data.quantity;
// console.log(firstName+ " - "+lastName);
if (data.plan == "none" || data.plan == "" || data.plan == "no") {
console.log(data)
var handler = PaystackPop.setup(
{
key: kkd_pff_settings.key,

0 comments on commit 50d7b22

Please sign in to comment.
You can’t perform that action at this time.