D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
thread-self
/
root
/
home
/
shubmkcj
/
urbane.createerp.com
/
PHP
/
Filename :
response.php
back
Copy
<?php session_start(); include_once("../config.php"); $params = $_REQUEST; $action = isset($params['action']) != '' ? $params['action'] : ''; $obj = new Response($conn); switch($action) { case 'getitemcodedata': $obj -> getitemcodedata($params); break; case 'getContactDetail': $obj -> getContactDetail($params); break; case 'updateContactDetail': $obj -> updateContactDetail($params); break; case 'deleteContactDetail': $obj -> deleteContactDetail($params); break; case 'addEditAddress': $obj -> addEditAddress($params); break; case 'getAddressDetail': $obj->getAddressDetail($params); break; case 'deleteAddressDetail': $obj->deleteAddressDetail($params); break; case 'getAvailableCredit': $obj->getAvailableCredit($params); break; case 'recordPayment': $obj->recordPayment($params); break; case 'recordPoPayment': $obj->recordPoPayment($params); break; case 'getCategoryById': $obj->getCategoryById($params); break; case 'addUpdateCategory': $obj->addUpdateCategory($params); break; case 'deleteCategory': $obj->deleteCategory($params); break; case 'cancelInvoice': $obj->cancelInvoice($params); break; case 'getPaidAmount': $obj->getPaidAmount($params); break; case 'AddTaxableResponse': $obj->addTaxableResponse($params); break; case 'AddNonTaxableResponse': $obj->addNonTaxableResponse($params); break; case 'PermanentDeleteExpense': $obj->permanentDeleteExpense($params); break; case 'DeleteExpense': $obj->deleteExpense($params); break; case 'GetExpenseById': $obj->getExpenseById($params); break; case 'RestoreExpense': $obj->restoreExpense($params); break; case 'deletePayment': $obj->deletePayment($params); break; case 'AddPayment': $obj->addPayment($params); break; case 'restoreContactDetail': $obj->restoreContactDetail($params); break; case 'permanentDeleteContact': $obj->permanentDeleteContact($params); break; case "AddCategory": $obj->addCategory($params); break; case 'DeleteItem': $obj->deleteItem($params); break; case 'DeleteProforma': $obj->deleteProforma($params); break; case 'DeletePacking': $obj->deletePacking($params); break; case 'DeleteManu': $obj->deletemanu($params); break; case 'deletePurchase': $obj->deletePurchase($params); break; case 'DeleteInvoice': $obj->deleteInvoice($params); break; case 'RestoreInvoice': $obj->restoreInvoice($params); break; case 'PermanentDeleteInvoice': $obj->permanentDeleteInvoice($params); break; case 'SuspendUser': $obj->suspendUser($params); break; case 'RestoreUser': $obj->restoreUser($params); break; case 'PermanentDeleteUser': $obj->permanentDeleteUser($params); break; case 'checkEmailAddress': $obj->checkEmailAddress($params); break; case 'ConvertInvoice': $obj->ConvertInvoice($params); break; case 'SuspendCompany': $obj->SuspendCompany($params); break; case 'restoreCompany': $obj->restoreCompany($params); break; case 'ChangePassword': $obj->changePassword($params); break; case 'GetPerforma': $obj->getPerforma($params); break; default: return; } class Response { protected $conn; protected $data = array(); function __construct($conn) { $this->conn = $conn; } function checkEmailAddress($params){ $email = addslashes(stripslashes($params["email"])); $retVal = $this->checkIfExist("SELECT * FROM login_admin WHERE email = '$email'"); if(! $retVal){ echo "SUCCESS"; }else{ echo "ERROR"; } } function getitemcodedata($params){ $itemcodeId = $params["getitemcodedata"]; $sqlGetcode = "SELECT *,(select price from proforma_item where item_id = '$itemcodeId' order by date_creation desc limit 1) as last_price FROM inventory WHERE id = '$itemcodeId'"; $resultGetcode = mysqli_query($this->conn, $sqlGetcode); if($resultGetcode){ if(mysqli_num_rows($resultGetcode) > 0){ $row = mysqli_fetch_assoc($resultGetcode); echo json_encode($row); } } } function getContactDetail($params){ $contactId = $params["contactId"]; $sqlGetContact = "SELECT * FROM contact WHERE id = '$contactId'"; $resultGetContact = mysqli_query($this->conn, $sqlGetContact); if($resultGetContact){ if(mysqli_num_rows($resultGetContact) > 0){ $row = mysqli_fetch_assoc($resultGetContact); echo json_encode($row); } } } function updateContactDetail($params){ $contactIdMain = $params["contactIdMain"]; $companyName = $params["bill_display_name"]; $contactPerson = $params["contact_person"]; $designation = $params["designation"]; $sqlUpdateContact = "UPDATE contact SET bill_display_name = '$companyName', contact_person_name = '$contactPerson', contact_person_designation = '$designation' WHERE id = '$contactIdMain'"; $resultUpdateContact = mysqli_query($this->conn, $sqlUpdateContact); if($resultUpdateContact){ echo "UPDATED"; }else{ echo "ERROR"; } } function deleteContactDetail($params){ $contactId = $params["contactId"]; $sqlDeleteContact = "UPDATE contact SET data_delete = 'yes' WHERE id = '$contactId'"; $resultDeleteContact = mysqli_query($this->conn, $sqlDeleteContact); if($resultDeleteContact){ echo "DELETED"; } else{ echo "ERROR"; } } function addEditAddress($params){ $actionType = $params["actionType"]; $contactId = $params["contactId"]; $addressId = $params["addressId"]; $address = addslashes(stripslashes($params["address"])); $country = addslashes(stripslashes($params["country"])); $state = addslashes(stripslashes($params["state"])); $city = addslashes(stripslashes($params["city"])); $pin = addslashes(stripslashes($params["pin"])); $gstin = addslashes(stripslashes($params["gstin"])); $email = addslashes(stripslashes($params["email"])); $phone = addslashes(stripslashes($params["phone"])); $bank_charges = addslashes(stripslashes($params["bank_charges"])); $iecno = addslashes(stripslashes($params["iecno"])); $type = addslashes(stripslashes($params["type"])); $panno = addslashes(stripslashes($params["panno"])); $currency = addslashes(stripslashes($params["currency"])); $opening_balance = addslashes(stripslashes($params["opening_balance"])); $terms_condtion = addslashes(stripslashes($params["terms_condtion"])); $sqlAddEditAddress = ""; $sql = " contact_address SET contact_id = '$contactId', address = '$address', city = '$city', state = '$state', country = '$country', pin = '$pin', email = '$email', phone = '$phone', gstin = '$gstin',`iecno`='$iecno',`type`='$type',`panno`='$panno',`currency`='$currency',`bank_charges`='$bank_charges',`opening_balance`='$opening_balance',`terms_condtion`='$terms_condtion'"; if(trim($actionType) == "add"){ $sqlAddEditAddress = " INSERT INTO " . $sql; }else{ $sqlAddEditAddress = " UPDATE " . $sql . " WHERE id = '$addressId'"; } $resultAddEditAddress = mysqli_query($this->conn, $sqlAddEditAddress); if($resultAddEditAddress){ if(trim($actionType) == "add"){ echo "ADDED"; }else{ echo "UPDATED"; } } else{ echo "ERROR"; } } function getAddressDetail($params){ $addressId = $params["addressId"]; $sqlGetAddress = "SELECT * FROM contact_address WHERE id = '$addressId'"; $resultGetAddress = mysqli_query($this->conn, $sqlGetAddress); if($resultGetAddress){ if(mysqli_num_rows($resultGetAddress) > 0){ $row = mysqli_fetch_assoc($resultGetAddress); echo json_encode($row); } } } function deleteAddressDetail($params){ $addressId = $params["addressId"]; $sqlDelete = "UPDATE contact_address SET is_deleted = 'YES' WHERE id = '$addressId'"; $resultDelete = mysqli_query($this->conn, $sqlDelete); if($resultDelete){ echo "DELETED"; } else{ echo "ERROR"; } } function getAvailableCredit($params){ $companyId = $params["companyId"]; $totalDebit = 0.00; $sqlGetDebit = "SELECT amount, tax_deduction FROM payment where company_id = '$companyId' AND transaction_type = 'Debit'"; $resultGetDebit = mysqli_query($this->conn,$sqlGetDebit); if(mysqli_num_rows($resultGetDebit) > 0){ while($row = mysqli_fetch_array($resultGetDebit)){ $totalDebit += $row["amount"]+ $row["tax_deduction"]; } } $totalCredit = 0.00; $sqlGetCredit = "SELECT amount, tax_deduction FROM payment where company_id = '$companyId' AND transaction_type = 'Credit'"; $resultGetCredit = mysqli_query($this->conn,$sqlGetCredit); if(mysqli_num_rows($resultGetCredit) > 0){ while($row = mysqli_fetch_array($resultGetCredit)){ $totalCredit += $row["amount"] + $row["tax_deduction"]; } } $availableCredit = $totalCredit - $totalDebit; $availableCredit = sprintf('%0.2f', $availableCredit); echo $availableCredit; } function recordPayment($params){ $invoiceId = $params["invoiceId"]; $companyId = $params["companyId"]; $referenceId = $params["referenceId"]; $invoice_referenceId = $params["invoice_referenceId"]; $availableCredit = $params["availableCredit"]; $taxdeduction = $params["taxdeduction"]; $useThis = isset($params["useThis"]) ? "YES" : "NO"; $amount = $params["amount"]; $remark = addslashes(stripslashes($params["remark"])); $dueAmount = $params["dueAmount"]; $createdBy = $params["createdBy"]; $mode = $params["payment_mode"]; $payment_date = $params["payment_date"]; $pDate = date('Y-m-d', strtotime($payment_date)); $sourceId = $params["sourceId"]; if($useThis == "YES"){ $totalAmount = $availableCredit + $amount; if($amount > 0){ $sqlInsertCredit1 = "INSERT into payment SET company_id = '$companyId', transaction_type = 'Credit', amount = '$amount', tax_deduction = '$taxdeduction', mode = '$mode', reference= '$referenceId', remark = '$remark', created_by = '$createdBy', source_id = '$sourceId', payment_date = '$pDate',transaction_reference_no='$invoice_referenceId',invoiceRow_ID='$invoiceId' "; $resultInsertCredit1 = mysqli_query($this->conn,$sqlInsertCredit1); } if($totalAmount >= $dueAmount){ $sqlInsertCredit = "INSERT into payment SET company_id = '$companyId', transaction_type = 'Debit', amount = '$dueAmount', tax_deduction = '$taxdeduction', mode = '', reference= '$referenceId', remark = '$remark', created_by = '$createdBy', source_id = '$sourceId' , payment_date = '$pDate',transaction_reference_no='$invoice_referenceId',invoiceRow_ID='$invoiceId' "; } else{ if($amount > 0){ $sqlInsertCredit = "INSERT into payment (company_id, transaction_type, amount, tax_deduction, mode, reference, remark, created_by, source_id, payment_date, transaction_reference_no,invoiceRow_ID) VALUES ('$companyId', 'Debit', '$availableCredit', '0.00', '', '$referenceId', '$remark', '$createdBy', '$sourceId', '$pDate','$invoice_referenceId','$invoiceId'), ('$companyId', 'Debit', '$amount', '$taxdeduction', '', '$referenceId', '$remark', '$createdBy', '$sourceId','$pDate','$invoice_referenceId','$invoiceId')"; } else{ $sqlInsertCredit = "INSERT into payment (company_id, transaction_type, amount, tax_deduction, mode, reference, remark, created_by, source_id, payment_date, transaction_reference_no,invoiceRow_ID) VALUES ('$companyId', 'Debit', '$availableCredit', '$taxdeduction', '', '$referenceId', '$remark', '$createdBy', '$sourceId', '$pDate','$invoice_referenceId','$invoiceId')"; } } } else{ if($amount >= $dueAmount){ $sqlInsertCredit = "INSERT into payment (company_id, transaction_type, amount, tax_deduction, mode, reference, remark, created_by, source_id, payment_date,transaction_reference_no,invoiceRow_ID) VALUES ('$companyId', 'Debit', '$amount', '$taxdeduction', '$mode', '$referenceId', '$remark', '$createdBy', '$sourceId', '$pDate','$invoice_referenceId','$invoiceId'), ('$companyId', 'Credit', '$amount', '$taxdeduction', '$mode', '$referenceId', '$remark', '$createdBy', '$sourceId', '$pDate','$invoice_referenceId','$invoiceId')"; } else{ $sqlInsertCredit = "INSERT into payment (company_id, transaction_type, amount, tax_deduction, mode, reference, remark, created_by, source_id, payment_date,transaction_reference_no,invoiceRow_ID) VALUES ('$companyId', 'Debit', '$amount', '$taxdeduction', '$mode', '$referenceId', '$remark', '$createdBy', '$sourceId', '$pDate','$invoice_referenceId','$invoiceId'), ('$companyId', 'Credit', '$amount', '$taxdeduction','$mode', '$referenceId', '$remark', '$createdBy', '$sourceId', '$pDate','$invoice_referenceId','$invoiceId')"; } } $resultInsertCredit = mysqli_query($this->conn,$sqlInsertCredit); if($resultInsertCredit){ if($amount > 0){ $this->conn->query("INSERT INTO invoice_notification SET invoice_id = '$invoiceId', notification_text = 'Payment Received INR $amount'"); } echo 1; } else{ echo "ERROR"; } } function recordPoPayment($params){ $paid_amount = $params["pay_amt"]; $details_payment_amount = $params["details_payment_amount"]; $payment_mode = $params["payment_mode"]; $payment_date = $params["payment_date"]; $remark = addslashes(stripslashes($params["remark"])); $manufacturer_id = $params["manufacturer_id"]; $po_no = addslashes(stripslashes($params["po_no"])); $po_row_id = $params["po_row_id"]; $pDate = date('Y-m-d', strtotime($payment_date)); $sourceId = $params["sourceId"]; $createdBy = addslashes(stripslashes($params["createdBy"])); $remark = addslashes(stripslashes($params["remark"])); $po_proforma_id = addslashes(stripslashes($params["po_proforma_id"])); $arrayId = explode(",", $po_no); $arr_po_row_id = explode(",", $po_row_id); $arrayinvoice_amt = explode(",", $details_payment_amount); $array_detail_profaram = explode(",", $po_proforma_id); $i = 1; $usd_amt = 0.00; $get_bpn = "SELECT * FROM `manufacturer` where id='$manufacturer_id'"; $get_b = mysqli_query($this->conn, $get_bpn); $get_bpn_row = mysqli_fetch_assoc($get_b); $manufacturer_currency = $get_bpn_row["currency"]; if($manufacturer_currency=='RMB') { $query_c="SELECT * FROM `conversion_rate` ORDER BY `conversion_rate`.`id` DESC LIMIT 1"; $result_c = mysqli_query($this->conn, $query_c); $row_c = mysqli_fetch_assoc($result_c); $last_rmb = $row_c["rmb"]; }else{ $last_rmb=1; } $count = count( $arr_po_row_id ); foreach ( $arrayinvoice_amt as $key => $amount ) { if ( $amount>$paid_amount ) { $remail = $amount-$paid_amount; $po_id = addslashes(stripslashes($arrayId[$key])); $po_row_id = addslashes(stripslashes($arr_po_row_id[$key])); $po_profaram = addslashes(stripslashes($array_detail_profaram[$key])); $paid_amount1=sprintf('%0.2f', ($paid_amount/$last_rmb)); $sqlInsertCredit1 = "INSERT into `purchase_order_payments` SET `manufacturer_id` = '$manufacturer_id', `po_no` = '$po_id', `po_row_id` = '$po_row_id', `transaction_type` = 'Credit', `amount` = '$paid_amount',`amount_in_usd`='$paid_amount1', `payment_mode`= '$payment_mode', `payment_date` = '$payment_date', `created_date` = '$pDate', `created_by` = '$createdBy', `source_id` = '$sourceId', `remarks`='$remark', `details_profroma_no`='$po_profaram', `details_payment_amount`='$details_payment_amount' "; $resultInsertCredit = mysqli_query($this->conn,$sqlInsertCredit1); $paid_amount = 0; } else { if ( $i == $count ) { $po_id = addslashes(stripslashes($arrayId[$key])); $po_row_id = addslashes(stripslashes($arr_po_row_id[$key])); $po_profaram = addslashes(stripslashes($array_detail_profaram[$key])); $paid_amount1=sprintf('%0.2f', ($paid_amount/$last_rmb)); $sqlInsertCredit1 = "INSERT into `purchase_order_payments` SET `manufacturer_id` = '$manufacturer_id', `po_no` = '$po_id', `po_row_id` = '$po_row_id', `transaction_type` = 'Credit', `amount` = '$paid_amount',`amount_in_usd`='$paid_amount1', `payment_mode`= '$payment_mode', `payment_date` = '$payment_date', `created_date` = '$pDate', `created_by` = '$createdBy', `source_id` = '$sourceId', `remarks`='$remark', `details_profroma_no`='$po_profaram', `details_payment_amount`='$details_payment_amount' "; $resultInsertCredit = mysqli_query($this->conn,$sqlInsertCredit1); break; } $po_id = addslashes(stripslashes($arrayId[$key])); $po_row_id = addslashes(stripslashes($arr_po_row_id[$key])); $po_profaram = addslashes(stripslashes($array_detail_profaram[$key])); $amount1=sprintf('%0.2f', ($amount/$last_rmb)); $sqlInsertCredit1 = "INSERT into `purchase_order_payments` SET `manufacturer_id` = '$manufacturer_id', `po_no` = '$po_id', `po_row_id` = '$po_row_id', `transaction_type` = 'Credit', `amount` = '$amount', `amount_in_usd`='$amount1',`payment_mode`= '$payment_mode', `payment_date` = '$payment_date', `created_date` = '$pDate', `created_by` = '$createdBy', `source_id` = '$sourceId', `remarks`='$remark', `details_profroma_no`='$po_profaram', `details_payment_amount`='$details_payment_amount' "; $resultInsertCredit = mysqli_query($this->conn,$sqlInsertCredit1); //$bal = pay_amt-amount; $paid_amount = $paid_amount-$amount; } $i++; } // $sqlInsertCredit1 = "INSERT into `purchase_order_payments` SET `manufacturer_id` = '$manufacturer_id', `po_no` = '$po_no', `po_row_id` = '$po_row_id', `transaction_type` = 'Credit', `amount` = '$pay_amt', `payment_mode`= '$payment_mode', `payment_date` = '$payment_date', `created_date` = '$pDate', `created_by` = '$createdBy', `source_id` = '$sourceId', `remarks`='$remark', `details_profroma_no`='$po_proforma_id', `details_payment_amount`='$details_payment_amount' "; // $resultInsertCredit = mysqli_query($this->conn,$sqlInsertCredit1); if($resultInsertCredit){ echo 1; } else{ echo "ERROR"; } } function getCategoryById($params){ $categoryId = $params["categoryId"]; $sqlGetCategory = "SELECT * FROM category WHERE id = '$categoryId'"; $resultGetCategory = mysqli_query($this->conn, $sqlGetCategory); if($resultGetCategory){ if(mysqli_num_rows($resultGetCategory) > 0){ $row = mysqli_fetch_assoc($resultGetCategory); echo json_encode($row); } } } function addUpdateCategory($params){ $id = $params["categoryId"]; $category = addslashes(stripslashes($params['category'])); $sourceId = $params['sourcedId']; if($this->checkIfExist("SELECT * FROM category WHERE id = '$id'")){ $sql = "UPDATE category SET category = '$category' WHERE id = '$id'"; } else{ $sql = "INSERT INTO category(category, source_id) VALUES ('$category', '$sourceId')"; } if( mysqli_query($this->conn, $sql)){ echo "SUCCESS"; }else{ echo "ERROR"; } } function deleteCategory($params){ $id = $params["categoryId"]; $sql = "UPDATE category SET is_deleted = 'YES' WHERE id = '$id'"; if(mysqli_query($this->conn, $sql)){ echo "SUCCESS"; } else{ echo "ERROR"; } } function cancelInvoice($params){ try{ $invoiceId = $params["invoiceId1"]; $cancelnote = addslashes(stripslashes($params["cancelnote"])); $refundMode = $params["refundMode"]; $paidAmountInput = $params["paidAmountInput"]; $createdBy = $params["createdBy"]; $companyId1 = $params["companyId1"]; $sourceId = $params["sourceId"]; $sql = "INSERT INTO cancelled_invoice(invoice_id, refund_mode, refund_amount, cancellation_notes, source_id) VALUES ('$invoiceId', '$refundMode', '$paidAmountInput', '$cancelnote', '$sourceId')"; if(mysqli_query($this->conn, $sql)){ if($refundMode == "Add to Credit"){ mysqli_query($this->conn, "INSERT INTO payment SET company_id = '$companyId1', transaction_type = 'Credit', amount = '$paidAmountInput', remark = 'Refund', created_by = '$createdBy', source_id = '$sourceId'"); } mysqli_query($this->conn, "UPDATE generate_invoice SET data_delete = 'cancel' WHERE id = '$invoiceId'"); $this->conn->query("INSERT INTO invoice_notification SET invoice_id = '$invoiceId', notification_text = 'Invoice cancelled <br> Remark - $cancelnote'"); echo "SUCCESS"; } else{ echo "ERROR"; } } catch(Exception $ex){ echo $ex->getMessage(); } } function getPaidAmount($params){ $referenceNo = $params["referenceNo"]; $amount = 0.00; $sqlGetPaidAmount = "SELECT amount, tax_deduction FROM payment WHERE reference = '$referenceNo' AND transaction_type = 'Debit'"; $resultGetPaidAmount = mysqli_query($this->conn, $sqlGetPaidAmount); if($resultGetPaidAmount){ if(mysqli_num_rows($resultGetPaidAmount) > 0){ while($rowGetPaidAmount = mysqli_fetch_assoc($resultGetPaidAmount)){ $amount += $rowGetPaidAmount["amount"] + $rowGetPaidAmount["tax_deduction"]; } } } $amount = sprintf('%0.2f', $amount); echo $amount; } function addTaxableResponse($params){ $id = $params["taxExpenseId"]; $taxSourceId = $params["taxSourceId"]; $dateOfExpense = addslashes(stripslashes($params["date_of_expense"])); $dateOfExpense = date("Y-m-d", strtotime($dateOfExpense)); $vendorName = addslashes(stripslashes($params["vendor_name"])); $vendorGSTIN = addslashes(stripslashes($params["vendor_gstin"])); $invoiceNo = addslashes(stripslashes($params["invoice_no"])); $itemName = addslashes(stripslashes($params["item_name"])); $amount = addslashes(stripslashes($params["amount"])); $cgst = addslashes(stripslashes($params["cgst"])); $sgst = addslashes(stripslashes($params["sgst"])); $igst = addslashes(stripslashes($params["igst"])); $paymentMode = addslashes(stripslashes($params["payment_mode"])); $paymentRemarks = addslashes(stripslashes($params["payment_remarks"])); $remarks = addslashes(stripslashes($params["remarks"])); $createdBy = addslashes(stripslashes($params["createdBy"])); $isTaxable = 'YES'; if(! $this->checkIfExist("SELECT * FROM expenses WHERE id = '$id'")){ $stmt = $this->conn->prepare("INSERT INTO expenses (is_taxable, date_of_expense, vendor_name, vendor_gst, invoice_no, item_name, amount, cgst, sgst, igst, payment_mode, payment_remarks, item_remarks, created_by, source_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param("ssssssddddssssi", $isTaxable, $dateOfExpense, $vendorName, $vendorGSTIN, $invoiceNo, $itemName, $amount, $cgst, $sgst, $igst, $paymentMode, $paymentRemarks, $remarks, $createdBy, $taxSourceId); } else{ $stmt = $this->conn->prepare("UPDATE expenses SET is_taxable = ?, date_of_expense = ?, vendor_name = ?, vendor_gst = ?, invoice_no = ?, item_name = ?, amount = ?, cgst = ?, sgst = ?, igst = ?, payment_mode = ?, payment_remarks = ?, item_remarks = ? WHERE id = ?"); $stmt->bind_param("ssssssddddsssd", $isTaxable, $dateOfExpense, $vendorName, $vendorGSTIN, $invoiceNo, $itemName, $amount, $cgst, $sgst, $igst, $paymentMode, $paymentRemarks, $remarks, $id); } $result = $stmt->execute(); if($result){ echo "SUCCESS"; } else{ echo "ERROR"; } } function addNonTaxableResponse($params){ $id = $params["ntExpenseId"]; $ntSourceId = $params["ntSourceId"]; $dateOfExpense = addslashes(stripslashes($params["nt_date_of_expense"])); $dateOfExpense = date("Y-m-d", strtotime($dateOfExpense)); $itemName = addslashes(stripslashes($params["nt_item_name"])); $amount = addslashes(stripslashes($params["nt_amount"])); $paymentMode = addslashes(stripslashes($params["nt_payment_mode"])); $remarks = addslashes(stripslashes($params["nt_remarks"])); $createdBy = addslashes(stripslashes($params["createdBy"])); $isTaxable = 'NO'; if(! $this->checkIfExist("SELECT * FROM expenses WHERE id = '$id'")){ $stmt = $this->conn->prepare("INSERT INTO expenses (is_taxable, date_of_expense, item_name, amount, payment_mode, item_remarks, created_by, source_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); $stmt->bind_param("sssdsssi", $isTaxable, $dateOfExpense, $itemName, $amount, $paymentMode, $remarks, $createdBy, $ntSourceId); } else{ $stmt = $this->conn->prepare("UPDATE expenses SET is_taxable = ?, date_of_expense = ?, item_name = ?, amount = ?, payment_mode = ?, item_remarks = ? WHERE id = ?"); $stmt->bind_param("sssdssi", $isTaxable, $dateOfExpense, $itemName, $amount, $paymentMode, $remarks, $id); } $result = $stmt->execute(); if($result){ echo "SUCCESS"; } else{ echo "ERROR"; } } function permanentDeleteExpense($params){ $id = $params["id"]; $sqlDeleteExpense = "DELETE FROM expenses WHERE id = ?"; $stmt = $this->conn->prepare($sqlDeleteExpense); $stmt->bind_param("i", $id); $resultDeleteExpense = $stmt->execute(); if($resultDeleteExpense){ echo "DELETED"; } else{ echo "ERROR"; } } function deleteExpense($params){ $id = $params["id"]; $isDeleted = "YES"; $sqlDeleteExpense = "UPDATE expenses SET is_deleted = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlDeleteExpense); $stmt->bind_param("si", $isDeleted, $id); $resultDeleteExpense = $stmt->execute(); if($resultDeleteExpense){ echo "DELETED"; } else{ echo "ERROR"; } } function getExpenseById($params){ $id = $params["id"]; $sqlGetExpense = "SELECT is_taxable, date_of_expense, vendor_name, vendor_gst, invoice_no, item_name, amount, cgst,sgst, igst, payment_mode, payment_remarks, item_remarks FROM expenses WHERE id = ?"; $stmt = $this->conn->prepare($sqlGetExpense); $stmt->bind_param("i", $id); $stmt->execute(); $result = $stmt->get_result(); // Binds the last executed statement as a result. echo json_encode(($result->fetch_assoc())); // Parse to JSON and print. } function restoreExpense($params){ $id = $params["id"]; $isDeleted = "NO"; $sqlRestoreExpense = "UPDATE expenses SET is_deleted = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlRestoreExpense); $stmt->bind_param("si", $isDeleted, $id); $resultRestoreExpense = $stmt->execute(); if($resultRestoreExpense){ echo "RESTORED"; } else{ echo "ERROR"; } } function deletePayment($params){ $id = $params["paymentId"]; $isDeleted = "YES"; $sqlDeletePayment = "UPDATE payment SET is_deleted = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlDeletePayment); $stmt->bind_param("si", $isDeleted, $id); $resultDeletePayment = $stmt->execute(); if($resultDeletePayment){ echo "DELETED"; } else{ echo "ERROR"; } } function addPayment($params){ try{ // $companyId = $params['companyId']; // $payment_mode = $params['payment_mode']; // $paymentDate = $params['paymentDate']; // $amount = $params['amount']; // $reference = addslashes(stripslashes($params['reference'])); // $transaction_reference_no = addslashes(stripslashes($params['transaction_reference_no'])); // $remark = addslashes(stripslashes($params['remark'])); // $created_by = $params['created_by']; // $sourceId = $params["sourceId"]; // $transactionType = 'Credit'; // $sql = "INSERT INTO payment(company_id, transaction_type, amount, mode, reference, payment_date, remark, created_by, source_id,transaction_reference_no) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; // $stmt = $this->conn->prepare($sql); // $stmt->bind_param("isdsssssis", $companyId, $transactionType, $amount, $payment_mode, $reference, $paymentDate, $remark, $created_by, $sourceId,$transaction_reference_no); // $result = $stmt->execute(); $companyId = $params['companyId']; $selectInvoiceRowId = $params['Client_invoice_row_Id']; $payment_mode = $params['payment_mode']; $paymentDate = $params['paymentDate']; $paid_amount = $params['amount']; $amounts_invoice = $params['Client_invoice_amt']; $bill_amount = $params['Client_invoice_totalant']; $reference = addslashes(stripslashes($params['reference'])); $transaction_reference_no = addslashes(stripslashes($params['transaction_reference_no'])); $remark = addslashes(stripslashes($params['remark'])); $created_by = $params['created_by']; $sourceId = $params["sourceId"]; $transactionType = 'Credit'; $arrayId = explode(",", $selectInvoiceRowId); $arrayInvoice = explode(",", $reference); $arrayRef = explode(",", $transaction_reference_no); $arrayinvoice_amt = explode(",", $amounts_invoice); $i = 1; $count = count( $arrayId ); foreach ( $arrayinvoice_amt as $key => $amount ) { if ( $amount>$paid_amount ) { $remail = $amount-$paid_amount; $reference = addslashes(stripslashes($arrayInvoice[$key])); $transaction_reference_no = addslashes(stripslashes($arrayRef[$key])); $sql = "INSERT INTO payment(company_id, transaction_type, amount, mode, reference, payment_date, remark, created_by, source_id,transaction_reference_no, invoiceRow_ID) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = $this->conn->prepare($sql); $stmt->bind_param("isdsssssiss", $companyId, $transactionType, $paid_amount, $payment_mode, $reference, $paymentDate, $remark, $created_by, $sourceId,$transaction_reference_no,$arrayId[$key]); $result = $stmt->execute(); $paid_amount = 0; } else { if ( $i == $count ) { $reference = addslashes(stripslashes($arrayInvoice[$key])); $transaction_reference_no = addslashes(stripslashes($arrayRef[$key])); $sql = "INSERT INTO payment(company_id, transaction_type, amount, mode, reference, payment_date, remark, created_by, source_id,transaction_reference_no, invoiceRow_ID) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = $this->conn->prepare($sql); $stmt->bind_param("isdsssssiss", $companyId, $transactionType, $paid_amount, $payment_mode, $reference, $paymentDate, $remark, $created_by, $sourceId,$transaction_reference_no,$arrayId[$key]); $result = $stmt->execute(); break; } $reference = addslashes(stripslashes($arrayInvoice[$key])); $transaction_reference_no = addslashes(stripslashes($arrayRef[$key])); $sql = "INSERT INTO payment(company_id, transaction_type, amount, mode, reference, payment_date, remark, created_by, source_id,transaction_reference_no, invoiceRow_ID) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; $stmt = $this->conn->prepare($sql); $stmt->bind_param("isdsssssiss", $companyId, $transactionType, $amount, $payment_mode, $reference, $paymentDate, $remark, $created_by, $sourceId,$transaction_reference_no,$arrayId[$key]); $result = $stmt->execute(); //$bal = pay_amt-amount; $paid_amount = $paid_amount-$amount; } $i++; } if ($result) { echo 1; } else { echo 0; } } catch(Expection $ex){ echo $ex.getMessage(); } } function restoreContactDetail($params){ $id = $params["contactId"]; $isDeleted = ""; $sqlRestore = "UPDATE contact_manager SET data_delete = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlRestore); $stmt->bind_param("si", $isDeleted, $id); $resultRestore = $stmt->execute(); if($resultRestore){ echo "RESTORED"; } else{ echo "ERROR"; } } function permanentDeleteContact($params){ $id = $params["contactId"]; $sqlDelete = "DELETE FROM contact_manager WHERE id = ?"; $stmt = $this->conn->prepare($sqlDelete); $stmt->bind_param("i", $id); $resultDelete = $stmt->execute(); if($resultDelete){ echo "DELETED"; } else{ echo "ERROR"; } } function addCategory($params){ $categoryName = addslashes(stripslashes($params['categoryName'])); $sourceId = $params['sourceId']; $sql = "INSERT INTO category(category, source_id) VALUES (?, ?)"; $stmt = $this->conn->prepare($sql); $stmt->bind_param("si", $categoryName, $sourceId); $result = $stmt->execute(); if($result){ echo "SUCCESS"; } else{ echo "ERROR"; } } function deleteItem($params){ $id = $params["itemId"]; $isDeleted = "yes"; $sqlDelete = "UPDATE inventory SET data_delete = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlDelete); $stmt->bind_param("si", $isDeleted, $id); $resultDelete = $stmt->execute(); if($resultDelete){ echo 1; } else{ echo "ERROR"; } } function deleteProforma($params){ $id = $params["proformaId"]; $isDeleted = "yes"; $sqlDelete = "UPDATE proforma SET data_delete = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlDelete); $stmt->bind_param("si", $isDeleted, $id); $resultDelete = $stmt->execute(); if($resultDelete){ echo "DELETED"; } else{ echo "ERROR"; } } function deletePacking($params){ $id = $params["packingId"]; $isDeleted = "yes"; $sqlDelete = "UPDATE packing_list SET data_delete = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlDelete); $stmt->bind_param("si", $isDeleted, $id); $resultDelete = $stmt->execute(); if($resultDelete){ echo "DELETED"; } else{ echo "ERROR"; } } function deletemanu($params){ $id = $params["manuId"]; $isDeleted = "yes"; $sqlDelete = "UPDATE manufacturer SET data_delete = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlDelete); $stmt->bind_param("si", $isDeleted, $id); $resultDelete = $stmt->execute(); if($resultDelete){ echo "DELETED"; } else{ echo "ERROR"; } } function deletePurchase($params){ $id = $params["purchaseId"]; $isDeleted = "yes"; $sqlDelete = "UPDATE purchase_order SET data_delete = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlDelete); $stmt->bind_param("si", $isDeleted, $id); $resultDelete = $stmt->execute(); if($resultDelete){ echo "DELETED"; } else{ echo "ERROR"; } } function deleteInvoice($params){ $id = $params["id"]; $isDeleted = "yes"; $sqlDelete = "UPDATE generate_invoice SET data_delete = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlDelete); $stmt->bind_param("si", $isDeleted, $id); $resultDelete = $stmt->execute(); if($resultDelete){ echo "DELETED"; } else{ echo "ERROR"; } } function permanentDeleteInvoice($params){ $id = $params["invoiceId"]; $sqlDelete = "DELETE FROM invoice_new WHERE id = ?"; $stmt = $this->conn->prepare($sqlDelete); $stmt->bind_param("i", $id); $resultDelete = $stmt->execute(); if($resultDelete){ echo "DELETED"; } else{ echo "ERROR"; } } function restoreInvoice($params){ $id = $params["invoiceId"]; $isDeleted = "NO"; $sqlDelete = "UPDATE generate_invoice SET data_delete = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlDelete); $stmt->bind_param("si", $isDeleted, $id); $resultDelete = $stmt->execute(); if($resultDelete){ echo "RESTORED"; } else{ echo "ERROR"; } } function suspendUser($params){ $id = $params["id"]; $isDeleted = "yes"; $sqlDelete = "UPDATE login_admin SET data_delete = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlDelete); $stmt->bind_param("si", $isDeleted, $id); $resultDelete = $stmt->execute(); if($resultDelete){ echo "SUSPENDED"; } else{ echo "ERROR"; } } function restoreUser($params){ $id = $params["id"]; $isDeleted = "no"; $sqlDelete = "UPDATE login_admin SET data_delete = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlDelete); $stmt->bind_param("si", $isDeleted, $id); $resultDelete = $stmt->execute(); if($resultDelete){ echo "RESTORED"; } else{ echo "ERROR"; } } function permanentDeleteUser($params){ $id = $params["id"]; $sqlDelete = "DELETE FROM login_admin WHERE id = ?"; $stmt = $this->conn->prepare($sqlDelete); $stmt->bind_param("i", $id); $resultDelete = $stmt->execute(); if($resultDelete){ echo "DELETED"; } else{ echo "ERROR"; } } function convertInvoice($params){ $invoice = $params["invoice"]; $invoice_id = $params["invoice_id"]; $invoice_number = $params["invoice_number"]; $type = "Invoice"; $sqlUpdateInvoice = "UPDATE invoice SET invoice_number = ?, invoice = ?, invoice_type = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlUpdateInvoice); $stmt->bind_param("issi", $invoice_number, $invoice_id, $type, $invoice); $resultUpdate = $stmt->execute(); if($resultUpdate){ $this->conn->query("INSERT INTO invoice_notification SET invoice_id = '$invoice', notification_text = 'Performa has been converted into invoice'"); echo "SUCCESS"; } else{ echo "ERROR"; } } function SuspendCompany($params){ $id = $params["id"]; $type = "yes"; $sqlSuspendCompany = "UPDATE company_details SET data_delete = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlSuspendCompany); $stmt->bind_param("si", $type, $id); $resultSuspendCompany = $stmt->execute(); if($resultSuspendCompany){ echo "SUSPENDED"; } else{ echo "ERROR"; } } function restoreCompany($params){ $id = $params["id"]; $type = "no"; $sqlRestoreCompany = "UPDATE company_details SET data_delete = ? WHERE id = ?"; $stmt = $this->conn->prepare($sqlRestoreCompany); $stmt->bind_param("si", $type, $id); $resultRestoredCompany = $stmt->execute(); if($resultRestoredCompany){ echo "RESTORED"; } else{ echo "ERROR"; } } function changePassword($params){ $output = ""; $username = addslashes(stripslashes($params["username"])); $password = md5(addslashes(stripslashes($params["password"]))); $new_password = addslashes(stripslashes($params["new_password"])); $con_password = addslashes(stripslashes($params["con_password"])); if($this->checkIfExist("SELECT * FROM login_admin WHERE email = '$username' AND password = '$password'")){ if($new_password === $con_password){ $pw = md5($new_password); $sqlUpdatePassword = "UPDATE login_admin SET password = ? WHERE email = ? AND password = ?"; $stmt = $this->conn->prepare($sqlUpdatePassword); $stmt->bind_param("sss", $pw, $username, $password); $result = $stmt->execute(); if($result){ $output = "CHANGED"; } else{ $output = "ERROR"; } } else{ $output = "MATCH"; } } else{ $output = "PASSWORD"; } echo $output; } function getPerforma($params){ $companyId = $params["companyId"]; $sqlGetPerforma = "SELECT max(performa_number) AS performa_number FROM invoice WHERE company_id = ?"; $stmt = $this->conn->prepare($sqlGetPerforma); $stmt->bind_param("i", $companyId); $stmt->execute(); $resultGetPerforma = $stmt->get_result(); if($resultGetPerforma->num_rows > 0){ while($rowGetPerforma = $resultGetPerforma->fetch_assoc()){ $performaNumber = $rowGetPerforma["performa_number"]; } } else{ $performaNumber = 0; } echo $performaNumber; } // Check if row Exists function checkIfExist($sql){ $resultSQL = mysqli_query($this->conn, $sql); if($resultSQL){ if(mysqli_num_rows($resultSQL) > 0){ return true; } } return false; } function getOneValueResultSet($SQL){ $output = ""; try{ $result = mysqli_query($this->conn, $SQL); if($result){ if(mysqli_num_rows($result) > 0){ while($row = mysqli_fetch_array($result)){ $output = $row[0]; } } } } catch(Exception $ex){ } return $output; } } ?>