Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,12 @@ function assets_supported()
$rest->delete('/:branch_id/:uuid', function ($branch_id, $uuid) use ($rest) {
$rest->sales->delete($rest, $branch_id, $uuid);
});

//added by Danish
$rest->post('/delete/:branch_id/:uuid', function ($branch_id, $uuid) use ($rest) {
$rest->sales->delete($rest, $branch_id, $uuid);
});

// All Sales
$rest->get('/:trans_type/', function ($trans_type) use ($rest) {
$rest->sales->get($rest, $trans_type);
Expand Down Expand Up @@ -524,5 +530,40 @@ function assets_supported()
});
// ------------------------------ Journal -------------------------------



// ------------------------------- Purchase ( Added by danish start ) --------------------------------
$rest->container->singleton('purchase', function () {
return new \FAAPI\Purchase();
});
$rest->group('/purchase', function () use ($rest) {
$rest->post('/', function () use ($rest) {
$rest->purchase->post($rest);
});
$rest->delete('/:branch_id/:uuid', function ($branch_id, $uuid) use ($rest) {
$rest->purchase->delete($rest, $branch_id, $uuid);
});
//added by Danish
$rest->post('/delete/:branch_id/:uuid', function ($branch_id, $uuid) use ($rest) {
$rest->purchase->delete($rest, $branch_id, $uuid);
});
});
// ------------------------------- Purchase ( Added by danish end ) --------------------------------


// ------------------------------- Customer Payments ( Added by danish start ) --------------------------------
$rest->container->singleton('customerPayments', function () {
return new \FAAPI\customerPayments();
});
$rest->group('/customerPayments', function () use ($rest) {
$rest->post('/', function () use ($rest) {
$rest->customerPayments->post($rest);
});
$rest->post('/delete', function () use ($rest) {
$rest->customerPayments->delete($rest);
});
});
// ------------------------------- Customer Payments ( Added by danish end ) --------------------------------

// Init API
$rest->run();
204 changes: 204 additions & 0 deletions purchase.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
<?php
/**
* Author : Danish Naseem <dani.115115@gmail.com>
*/

$path_to_root = "../..";

$page_security = 'SA_PURCHASEORDER';
include_once($path_to_root . "/sales/includes/cart_class.inc");
include_once($path_to_root . "/purchasing/includes/po_class.inc");
//include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
include_once($path_to_root . "/purchasing/includes/db/suppliers_db.inc");
include_once($path_to_root . "/reporting/includes/reporting.inc");
include_once($path_to_root . "/includes/types.inc");


function purchase_add() {

$app = \Slim\Slim::getInstance('SASYS');
$req = $app->request();
$info = $req->post();
/*$cart = null;
$cart = new Cart($info['trans_type'], 20);*/

$purchase_obj=new purch_order();
foreach ($info as $key => $value) {
$purchase_obj->{$key} = $value;
}
$line_items=[];
foreach ($purchase_obj->line_items as $k =>$v){
$line_items[]=new po_line_details($v['line_no'], $v['stock_id'], $v['item_description'], $v['quantity'], $v['price'], $v['units'], $v['req_del_date'], $v['qty_inv'], $v['qty_received'], $v['grn_item_id']);
}
$purchase_obj->line_items=$line_items;
$purchase_obj->orig_order_date=$info['orig_order_date'];
$purchase_obj->tax_included=$info['tax_included'];
$purchase_obj->trans_type=ST_SUPPINVOICE;
$purchase_obj->reference=$info['ref'];

$_SESSION['PO']=$purchase_obj;
if (can_commit()) {
$cart=$_SESSION['PO'];
$trans_no = add_direct_supp_trans($cart);
if($trans_no){
api_success_response(sprintf(_("Invoice # %d has been entered."), $trans_no));
}else{
api_error(412, 'Failed to add invoice.');
}
}else{
api_error(500, 'Invoice data is invalid.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User code, like this php, shouldn't return a 5xx response. Use a 4xx response instead. I'd recommend 400 Bad Request. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses

}


}

function can_commit()
{
if (!get_post('supplier_id'))
{
display_error(_("There is no supplier selected."));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why "display_error" is being called from the API which has no ui? I'm not sure why this code is here.

set_focus('supplier_id');
return false;
}

if (!is_date($_POST['OrderDate']))
{
display_error(_("The entered order date is invalid."));
set_focus('OrderDate');
return false;
}
if (($_SESSION['PO']->trans_type == ST_SUPPRECEIVE || $_SESSION['PO']->trans_type == ST_SUPPINVOICE)
&& !is_date_in_fiscalyear($_POST['OrderDate'])) {
display_error(_("The entered date is out of fiscal year or is closed for further data entry."));
set_focus('OrderDate');
return false;
}

if (($_SESSION['PO']->trans_type==ST_SUPPINVOICE) && !is_date($_POST['due_date']))
{
display_error(_("The entered due date is invalid."));
set_focus('due_date');
return false;
}

if (!$_SESSION['PO']->order_no)
{
if (!check_reference(get_post('ref'), $_SESSION['PO']->trans_type))
{
set_focus('ref');
return false;
}
}

if ($_SESSION['PO']->trans_type == ST_SUPPINVOICE && trim(get_post('supp_ref')) == false)
{
display_error(_("You must enter a supplier's invoice reference."));
set_focus('supp_ref');
return false;
}
if ($_SESSION['PO']->trans_type==ST_SUPPINVOICE
&& is_reference_already_there($_SESSION['PO']->supplier_id, get_post('supp_ref'), $_SESSION['PO']->order_no))
{
display_error(_("This invoice number has already been entered. It cannot be entered again.") . " (" . get_post('supp_ref') . ")");
set_focus('supp_ref');
return false;
}
if ($_SESSION['PO']->trans_type == ST_PURCHORDER && get_post('delivery_address') == '')
{
display_error(_("There is no delivery address specified."));
set_focus('delivery_address');
return false;
}
if (get_post('StkLocation') == '')
{
display_error(_("There is no location specified to move any items into."));
set_focus('StkLocation');
return false;
}
if (!db_has_currency_rates($_SESSION['PO']->curr_code, $_POST['OrderDate'], true))
return false;
if ($_SESSION['PO']->order_has_items() == false)
{
display_error (_("The order cannot be placed because there are no lines entered on this order."));
return false;
}
if (floatcmp(input_num('prep_amount'), $_SESSION['PO']->get_trans_total()) > 0)
{
display_error(_("Required prepayment is greater than total invoice value."));
set_focus('prep_amount');
return false;
}

return true;
}

function purchase_delete($branch_id,$uuid){
$resp=['status'=>true,'msg'=>''];
try {
$_POST['filterType']=ST_SUPPINVOICE;
if (check_valid_entries()==true)
{
$void_entry = get_voided_entry($_POST['filterType'], $_POST['trans_no']);
if ($void_entry != null)
{
$resp['status']=false;
$resp['error_code']=500;
$resp['msg']="The selected transaction has already been voided.";

} else {
$msg = void_transaction($_POST['filterType'], $_POST['trans_no'], $_POST['date_'], $_POST['memo_']);
if (!$msg) {
$resp['status'] = true;
} else {
$resp['status'] = false;
$resp['error_code'] = 500;
$resp['msg'] = $msg;
}
}
}
} catch (Exception $e) {
error_log($e->getMessage(), 3, "/var/tmp/sales_cancel.log");
$resp['msg']='Could not cancel invoice. ';
return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails very quietly. Why not use an api_error

}
if($resp['status']){
api_success_response($resp);
}else{
api_error($resp['error_code'], $resp['msg']);
}

}

function check_valid_entries()
{
if (is_closed_trans($_POST['filterType'],$_POST['trans_no']))
{
display_error(_("The selected transaction was closed for edition and cannot be voided."));
set_focus('trans_no');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

display_error and set_focus looks like ui code from FA. Not sure that this is appropriate for the API

return false;
}
if (!is_date($_POST['date_']))
{
display_error(_("The entered date is invalid."));
set_focus('date_');
return false;
}
if (!is_date_in_fiscalyear($_POST['date_']))
{
display_error(_("The entered date is out of fiscal year or is closed for further data entry."));
set_focus('date_');
return false;
}

if (!is_numeric($_POST['trans_no']) OR $_POST['trans_no'] <= 0)
{
display_error(_("The transaction number is expected to be numeric and greater than zero."));
set_focus('trans_no');
return false;
}
return true;
}


?>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing tags aren't needed these days. But, does no harm.

84 changes: 83 additions & 1 deletion sales.inc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ include_once($path_to_root . "/sales/includes/db/cust_trans_details_db.inc");
include_once($path_to_root . "/sales/includes/sales_db.inc");
include_once($path_to_root . "/sales/includes/db/sales_types_db.inc");
include_once($path_to_root . "/admin/db/attachments_db.inc");
include_once($path_to_root . "/includes/types.inc");
// include_once($path_to_root . "/modules/timbrado/includes/db/comprobantes_db.php.inc");
// include_once($path_to_root . "/modules/timbrado/includes/db/llavero_db.php.inc");
// include_once($path_to_root . "/modules/timbrado/includes/generate/AutoFacturaCore.php.inc");
Expand Down Expand Up @@ -468,7 +469,7 @@ function sales_edit($trans_no, $trans_type) {
api_success_response(_("Ok"));
}

function sales_cancel($branch_id, $uuid) {
function sales_cancel__($branch_id, $uuid) {
error_log("\r\n1", 3, "/var/tmp/sasys.log");
$AutoFactura = new AutoFacturaCore();
$AutoFactura->userkey = get_cofig("Llave de Usuario", "");
Expand Down Expand Up @@ -497,6 +498,87 @@ function sales_cancel($branch_id, $uuid) {
}
}



/**
* Author : Danish Naseem
* <dani.115115@gmail.com>
*/

function sales_cancel($branch_id, $uuid) {
$resp=['status'=>true,'msg'=>''];
try {
$_POST['filterType']=ST_SALESINVOICE;
$check=check_valid_entries();

if ($check['status'])
{
$void_entry = get_voided_entry($_POST['filterType'], $_POST['trans_no']);
if ($void_entry != null)
{
$resp['status']=false;
$resp['error_code']=500;
$resp['msg']="The selected transaction has already been voided.";
} else {
$msg = void_transaction($_POST['filterType'], $_POST['trans_no'], $_POST['date_'], $_POST['memo_']);
if (!$msg) {
$resp['status'] = true;
} else {
$resp['status'] = false;
$resp['error_code'] = 500;
$resp['msg'] = $msg;
}
}
}else{
$resp['status'] = false;
$resp['error_code'] = 500;
$resp['msg'] = $check['msg'];
}
} catch (Exception $e) {
error_log($e->getMessage(), 3, "/var/tmp/sales_cancel.log");
$resp['msg']='Could not cancel invoice. ';
return;
}
if($resp['status']){
api_success_response($resp);
}else{
api_error($resp['error_code'], $resp['msg']);
}
}

/**
* Author : Danish Naseem
* <dani.115115@gmail.com>
*/
function check_valid_entries()
{
$check=array('status'=>true,'msg');

if (is_closed_trans($_POST['filterType'],$_POST['trans_no']))
{
$check['msg'] = "The selected transaction was closed for edition and cannot be voided.";
$check['status'] = false;
}
if (!is_date($_POST['date_']))
{
$check['msg'] = "The entered date is invalid.";
$check['status'] = false;
}
if (!is_date_in_fiscalyear($_POST['date_']))
{
$check['msg'] ="The entered date is out of fiscal year or is closed for further data entry.";
$check['status'] = false;
}

if (!is_numeric($_POST['trans_no']) OR $_POST['trans_no'] <= 0)
{
$check['msg'] ="The transaction number is expected to be numeric and greater than zero.";
$check['status'] = false;
}

return $check;
}

function can_process($info, $cart) {
global $Refs;

Expand Down
21 changes: 21 additions & 0 deletions src/CustomerPayments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Author : Danish Naseem <dani.115115@gmail.com>
*/

namespace FAAPI;

class CustomerPayments
{
public function post($rest)
{
include_once(API_ROOT . "/customerPayments.inc");
customerPayments_add();
}

public function delete($rest)
{
include_once(API_ROOT . "/customerPayments.inc");
customerPayments_delete();
}
}
1 change: 1 addition & 0 deletions src/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ public function post($rest)
}
$cust = get_customer($selected_id);
if ($cust != null) {
$cust['selected_branch']=$selected_branch;
api_create_response(json_encode($cust));
} else {
api_error(500, 'Could Not Save to Database');
Expand Down
Loading