Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #29725 Doesn't create new invoice after payment #30194

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
12 changes: 12 additions & 0 deletions htdocs/takepos/ajax/ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,16 @@

$printer = new dolReceiptPrinter($db);
$printer->sendToPrinter($object, getDolGlobalString('TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$term), getDolGlobalString('TAKEPOS_PRINTER_TO_USE'.$term));
} elseif ($action == 'createNewInvoice') {
top_httphead('application/json');

require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';

$invoice = new Facture($db);
$result = $invoice->create($user);
if ($result > 0) {
echo json_encode(array('invoiceid' => $invoice->id));
} else {
echo json_encode(array('error' => 'Failed to create invoice'));
}
}
37 changes: 32 additions & 5 deletions htdocs/takepos/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,16 +540,43 @@ function ClickProduct(position, qty = 1) {
console.log("Click on product at position "+position+" for idproduct "+idproduct+", qty="+qty+" invoicdeid="+invoiceid);
if (idproduct=="") return;
// Call page invoice.php to generate the section with product lines
$("#poslines").load("invoice.php?action=addline&token=<?php echo newToken() ?>&place="+place+"&idproduct="+idproduct+"&qty="+qty+"&invoiceid="+invoiceid, function() {
<?php if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
echo "CustomerDisplay();";
}?>
});
if (invoiceid == "") {
createNewInvoice(idproduct, qty);
} else {
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=getInvoice&token=<?php echo newToken(); ?>&id=' + invoiceid, function (data) {
if (data['paye'] == 1 && data['status'] == <?php echo Facture::STATUS_CLOSED; ?>) {
console.log("Creating new invoice");
createNewInvoice(idproduct, qty);
} else if (data['paye'] == 0 && data['status'] == <?php echo Facture::STATUS_DRAFT; ?>) {
console.log("Adding product to invoice");
addProductToInvoice(idproduct, qty, invoiceid);
} else if (data['paye'] == 0 && data['status'] == <?php echo Facture::STATUS_VALIDATED; ?>) {
console.log("Invoice not completely paid");
alert('Invoice not completely paid !');
}
});
}
}

ClearSearch(false);
}

function createNewInvoice(idproduct, qty) {
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=createNewInvoice&token=<?php echo newToken();?>', function (data) {
invoiceid = data['invoiceid'];
$("#invoiceid").val(invoiceid);
addProductToInvoice(idproduct, qty, invoiceid);
});
}

function addProductToInvoice(idproduct, qty, invoiceid) {
$("#poslines").load("invoice.php?action=addline&token=<?php echo newToken() ?>&place="+place+"&idproduct="+idproduct+"&qty="+qty+"&invoiceid="+invoiceid, function() {
<?php if (getDolGlobalString('TAKEPOS_CUSTOMER_DISPLAY')) {
echo "CustomerDisplay();";
}?>
});
}

function ChangeThirdparty(idcustomer) {
console.log("ChangeThirdparty");
// Call page list.php to change customer
Expand Down
1 change: 1 addition & 0 deletions htdocs/takepos/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ function fail($message)
$prod = new Product($db);
$prod->fetch($idproduct);


$customer = new Societe($db);
$customer->fetch($invoice->socid);

Expand Down