Skip to content

Commit

Permalink
Added inventory management
Browse files Browse the repository at this point in the history
  • Loading branch information
lukman-paystack committed Jun 13, 2019
1 parent 42fa86b commit 50d7b22
Show file tree
Hide file tree
Showing 23 changed files with 138 additions and 12 deletions.
42 changes: 38 additions & 4 deletions admin/class-paystack-forms-admin.php
Expand Up @@ -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 == "") {
Expand All @@ -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';
}
Expand All @@ -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" />
Expand Down Expand Up @@ -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'];
Expand Down
2 changes: 1 addition & 1 deletion includes/class-paystack-forms-activator.php
Expand Up @@ -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,
Expand Down
54 changes: 47 additions & 7 deletions public/class-paystack-forms-public.php
Expand Up @@ -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>";
Expand Down Expand Up @@ -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>';
Expand All @@ -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>';
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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"], ""),
Expand Down Expand Up @@ -1590,6 +1626,10 @@ function kkd_pff_paystack_submit_action()
'txnbearer' => $txnbearer,
'transaction_charge' => $transaction_charge
);

//-------------------------------------------------------------------------------------------


echo json_encode($response);
die();
}
Expand Down
51 changes: 51 additions & 0 deletions public/css/pff-paystack-style.css
Expand Up @@ -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
=============================== */
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Binary file added public/fonts/Graphik-Black.otf
Binary file not shown.
Binary file added public/fonts/Graphik-BlackItalic.otf
Binary file not shown.
Binary file added public/fonts/Graphik-Bold.otf
Binary file not shown.
Binary file added public/fonts/Graphik-BoldItalic.otf
Binary file not shown.
Binary file added public/fonts/Graphik-Extralight.otf
Binary file not shown.
Binary file added public/fonts/Graphik-ExtralightItalic.otf
Binary file not shown.
Binary file added public/fonts/Graphik-Light.otf
Binary file not shown.
Binary file added public/fonts/Graphik-LightItalic.otf
Binary file not shown.
Binary file added public/fonts/Graphik-Medium.otf
Binary file not shown.
Binary file added public/fonts/Graphik-MediumItalic.otf
Binary file not shown.
Binary file added public/fonts/Graphik-Regular.otf
Binary file not shown.
Binary file added public/fonts/Graphik-RegularItalic.otf
Binary file not shown.
Binary file added public/fonts/Graphik-Semibold.otf
Binary file not shown.
Binary file added public/fonts/Graphik-SemiboldItalic.otf
Binary file not shown.
Binary file added public/fonts/Graphik-Super.otf
Binary file not shown.
Binary file added public/fonts/Graphik-SuperItalic.otf
Binary file not shown.
Binary file added public/fonts/Graphik-Thin.otf
Binary file not shown.
Binary file added public/fonts/Graphik-ThinItalic.otf
Binary file not shown.
1 change: 1 addition & 0 deletions public/js/paystack-forms-public.js
Expand Up @@ -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,
Expand Down

0 comments on commit 50d7b22

Please sign in to comment.