require_once ('header.php'); include_once ('dbconn.php'); if ($_SESSION['auth_type'] == "STORE-FREE") { include_once('upgrade_required.php'); exit(); } else if ($_SESSION['auth_type'] == 'DENIED') { include_once('access_denied_text.php'); exit(); } session_start(); $total_purchase_ref = $_SESSION['total_purchases']; if($_SESSION['auth_type'] == "MASTER-ADMIN") { $store_id = intval (string_decrypt($store_id)); } if ($total_purchase_ref == 0.00){ $query = "select SUM(cost_value) as total_purchases from store_purchases where store_id = $store_id AND stocktake_id = '$stocktake_id';"; $retval = f_read_column('total_purchases', $query, $total_purchases); $total_purchase_ref = $total_purchases; } else { $total_purchase_ref = $_SESSION['total_purchases']; } $store_id = intval($_SESSION['store_id']); $query = "select * from view_stocktake_master where store_id = $store_id order by stock_date desc limit 1"; $retval = f_read_column('id', $query, $stocktake_id); $action = $_POST['action']; $query = "Select id as data_value, stock_date_str as data_name from view_stocktake_master"; $id_value = "stocktake_id"; $name_value = "stocktake_id"; $store_name = f_htmlspecialchars_decode($datarows[0]->store_name , ENT_QUOTES); //$lstr_stock_date_str = "For " . f_htmlspecialchars_decode($datarows[0]->stock_date_str , ENT_QUOTES); $lstr_stocktake_sel = f_get_dropdown("id", "stock_date_str", "view_stocktake_master", '', "stocktake_id_sel", "store_id = '$store_id'", '', '', ' id desc', true, false, true); $lstr_department_select = f_get_dropdown("id", "department_name", "store_departments", '', "store_department_select", "store_id = '$store_id'", '', '', ' id desc', true, false, true); if($action == 'add_purchase') { //echo 'Do you get even here?'; $supplier_id = $_POST['supplier_id']; $delivery_number = $_POST['delivery_number']; $po_number = $_POST['po_number']; $delivery_date = $_POST['delivery_date']; $cost_value = $_POST['cost_value']; $stocktake_id_sale = $_POST['stocktake_id']; $stocktake_id_val = intval (string_decrypt($stocktake_id_sale)); $department_id = string_decrypt($_POST['department_id']); $chckValue = $_POST['chckValue']; $cost_value = str_replace(',', '', $cost_value); $change_resolve = $_POST['change_resolve']; $change_resolve_id = $_POST['change_resolve_id']; if ($po_number == '') $po_number = 0; if ($supplier_id == '') $supplier_id = 0; $delivery_date = strtotime($delivery_date); $delivery_date = date('Y-m-d',$delivery_date); if ($delivery_number == '') $delivery_number = 0; if ($delivery_date == '1969-12-31') $delivery_date = '2018-01-01'; if ($chckValue == 'false') { if($change_resolve == '' && $change_resolve_id == '') { $query = "insert into store_purchases (supplier_id, date, delivery_number, po_number, cost_value, store_id, stocktake_id, purchase_added) values ('$supplier_id', '$delivery_date', '$delivery_number','$po_number','$cost_value', '$store_id', '$stocktake_id_val' , NOW())"; } else { $query = "insert into store_purchases (supplier_id, date, delivery_number, po_number, cost_value, store_id, stocktake_id, comments, purchase_added) values ('$supplier_id', '$delivery_date', '$delivery_number','$po_number','$cost_value', '$store_id', '$stocktake_id_val' , 'Purchase Added', NOW())"; } } else { if($change_resolve == '' && $change_resolve_id == '') { $query = "insert into store_purchases (supplier_id, date, delivery_number, po_number, cost_value, store_id, stocktake_id, department_id, purchase_added) values ('$supplier_id', '$delivery_date', '$delivery_number','$po_number','$cost_value', '$store_id', '$stocktake_id_val', $department_id, NOW())"; } else { $query = "insert into store_purchases (supplier_id, date, delivery_number, po_number, cost_value, store_id, stocktake_id, department_id, comments, purchase_added) values ('$supplier_id', '$delivery_date', '$delivery_number','$po_number','$cost_value', '$store_id', '$stocktake_id_val', $department_id, 'Purchase Added', NOW())"; } } $ret = f_insert_query($query, $rows, $last_id); echo $query; } if($action == 'add_purchase_itemised') { //echo 'Do you get even here?'; $supplier_id = $_POST['supplier_id']; $delivery_number = $_POST['delivery_number']; $po_number = $_POST['po_number']; $delivery_date = $_POST['delivery_date']; $cost_value = $_POST['cost_value']; $product_name = $_POST['product_name']; $purchase_quantity = $_POST['purchase_quantity']; $product_id = $_POST['product_id']; $stocktake_id_sale = $_POST['stocktake_id']; $stocktake_id_val = intval (string_decrypt($stocktake_id_sale)); $cost_value = str_replace(',', '', $cost_value); $change_resolve = $_POST['change_resolve']; $change_resolve_id = $_POST['change_resolve_id']; if ($po_number == '') $po_number = 0; if ($supplier_id == '') $supplier_id = 0; $delivery_date = strtotime($delivery_date); $delivery_date = date('Y-m-d',$delivery_date); if ($delivery_number == '') $delivery_number = 0; if ($delivery_date == '1969-12-31') $delivery_date = '2018-01-01'; $query1 = "select sd.* from store_departments sd left join product_master pm on pm.department_id = sd.id where sd.store_id = $store_id and pm.product_name LIKE '%$product_name%'"; $retval = f_read_column('id', $query1, $department_id); if($change_resolve == '' && $change_resolve_id == '') { $query = "insert into store_purchases (supplier_id, date, delivery_number, po_number, cost_value, store_id, stocktake_id, product_name, product_id, quantity, department_id, purchase_added) values ('$supplier_id', '$delivery_date', '$delivery_number','$po_number','$cost_value', '$store_id', '$stocktake_id_val', '$product_name', '$product_id', '$purchase_quantity', '$department_id', NOW())"; } else { $query = "insert into store_purchases (supplier_id, date, delivery_number, po_number, cost_value, store_id, stocktake_id, product_name, product_id, quantity, department_id, comments, purchase_added) values ('$supplier_id', '$delivery_date', '$delivery_number','$po_number','$cost_value', '$store_id', '$stocktake_id_val', '$product_name', '$product_id', '$purchase_quantity', '$department_id', 'Purchase Added', NOW())"; } // echo $query; //die(); $ret = f_insert_query($query, $rows, $last_id); //echo $query; } else if ($action == 'update_purchase') { // $supplier_id = $_POST['supplier_id']; $purch_id = $_POST['purch_id']; $purch_date = $_POST['purch_date']; //echo "Purchase date: " . $purch_date; $purch_numb = $_POST['purch_numb']; $purch_cost = $_POST['purch_cost']; $supplier_id = string_decrypt($_POST['supplier_id']); $delivery_date = strtotime($purch_date); $delivery_date = date('Y-m-d',$delivery_date); $purch_cost = str_replace(',', '', $purch_cost); $change_resolve = $_POST['change_resolve']; $change_resolve_id = $_POST['change_resolve_id']; if ($supplier_id == '') $supplier_id = 0; if ($delivery_number == '') $delivery_number = 0; if ($supplier_name == '') $supplier_name = 'N/A'; if($change_resolve == '' && $change_resolve_id == '') { $update_purchase_qry = " UPDATE store_purchases SET supplier_id = '$supplier_id', date = '$delivery_date', delivery_number = '$purch_numb', cost_value = '$purch_cost' , comments = '', purchase_edited = NOW() WHERE id = '$purch_id';"; } else { $update_purchase_qry = " UPDATE store_purchases SET supplier_id = '$supplier_id', date = '$delivery_date', delivery_number = '$purch_numb', cost_value = '$purch_cost', comments = 'Purchase Edited', purchase_edited = NOW() WHERE id = '$purch_id';"; } //echo $update_purchase_qry; //die(); $ret = f_update_query($update_purchase_qry, $rows); } else if ($action == 'add_supp') { $lstr_supplier_name = f_htmlspecialchars($_POST['supplier_name'], ENT_QUOTES); $lstr_address = f_htmlspecialchars($_POST['address'], ENT_QUOTES); $lstr_city = f_htmlspecialchars($_POST['city'], ENT_QUOTES); $lstr_county = f_htmlspecialchars($_POST['county'], ENT_QUOTES); $lstr_region = f_htmlspecialchars($_POST['region'], ENT_QUOTES); $lstr_country = f_htmlspecialchars($_POST['country'], ENT_QUOTES); $lstr_created_date = date_to_db(f_htmlspecialchars($_POST['created_date'], ENT_QUOTES)); $lstr_email_id = f_htmlspecialchars($_POST['email_id'], ENT_QUOTES); $lstr_mobile = f_htmlspecialchars($_POST['mobile'], ENT_QUOTES); $lstr_phone = f_htmlspecialchars($_POST['phone'], ENT_QUOTES); $lstr_state = f_htmlspecialchars($_POST['state'], ENT_QUOTES); $lstr_status = f_htmlspecialchars($_POST['status'], ENT_QUOTES); if ($lstr_supplier_name == '') $lstr_supplier_name = 'N/A'; if ($lstr_address == '') $lstr_address = 'N/A'; if ($lstr_city == '') $lstr_city = 'N/A'; if ($lstr_county == '') $lstr_county = 'N/A'; if ($lstr_region == '') $lstr_region = 'N/A'; if ($lstr_country == '') $lstr_country = 'N/A'; if ($lstr_email_id == '') $lstr_email_id = 'N/A'; if ($lstr_phone == '') $lstr_phone = 'N/A'; $query = "insert into supplier_master (address,city,county,region,country,created_date,email_id,mobile,phone,state,status,supplier_name,zip, store_id) values ('$lstr_address','$lstr_city','$lstr_county','$lstr_region','$lstr_country','$lstr_created_date','$lstr_email_id','$lstr_mobile','$lstr_phone','$lstr_state','$lstr_status','$lstr_supplier_name','$lstr_zip','$store_id')"; $ret = f_insert_query($query, $rows, $last_id); } //other actions ?>
 Purchase Created successfully!
	   Purchase Created successfully! Purchase Failed to create
	   Purchase Failed to create Purchase Edited successfully!
	   Purchase Edited successfully! Purchase Deleted successfully!
	   Purchase Deleted successfully! Supplier Created successfully!
	   Supplier Created successfully! Supplier Failed to create
	   Supplier Failed to create