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
25 changes: 25 additions & 0 deletions invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
$desc = GETPOST('desc');
$pay = GETPOST('pay');

function fail($message){
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
die($message);
}

$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."facture where facnumber='ProvPOS-$place'";
$resql = $db->query($sql);
$row = $db->fetch_array ($resql);
Expand All @@ -52,6 +57,26 @@
$now=dol_now();
$invoice = new Facture($db);
$invoice->fetch($placeid);
if($invoice->total_ttc<0){
$invoice->type= $invoice::TYPE_CREDIT_NOTE;
$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."facture WHERE ";
$sql.="fk_soc = '".$invoice->socid."' ";
$sql.="AND type <> ".Facture::TYPE_CREDIT_NOTE." ";
$sql.="AND fk_statut >= ".$invoice::STATUS_VALIDATED." ";
$sql.="ORDER BY rowid DESC";
$resql = $db->query($sql);
if($resql){
$obj = $db->fetch_object($resql);
$fk_source=$obj->rowid;
if($fk_source == null){
fail($langs->transnoentitiesnoconv("NoPreviousBillForCustomer"));
}
}else{
fail($langs->transnoentitiesnoconv("NoPreviousBillForCustomer"));
}
$invoice->fk_facture_source=$fk_source;
$invoice->update($user);
}
if (! empty($conf->stock->enabled) and $conf->global->CASHDESK_NO_DECREASE_STOCK!="1") $invoice->validate($user, '', $conf->global->CASHDESK_ID_WAREHOUSE);
else $invoice->validate($user);
// Add the payment
Expand Down
3 changes: 2 additions & 1 deletion langs/en_US/takepos.lang
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ Floor=Floor
AddTable=Add table
Place=Place
TakeboxNecesary='TakeBOX' application required
OrderPrinters=Order printers
OrderPrinters=Order printers
NoPreviousBillForCustomer=Cannot do negative bill without previous bill for current customer
3 changes: 2 additions & 1 deletion langs/fr_FR/takepos.lang
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ Floor=Étage
AddTable=Ajouter une table
Place=Endroit
TakeboxNecesary='TakeBOX' Application requise
OrderPrinters=Commande imprimantes
OrderPrinters=Commande imprimantes
NoPreviousBillForCustomer=Impossible de créer une facture négative sans une facture précédente pour le client courant
12 changes: 8 additions & 4 deletions pay.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function addreceived(price)
$('#change1').html(received.toFixed(2));
if (received><?php echo $invoice->total_ttc;?>)
{
var change=parseFloat(received-<?php echo $invoice->total_ttc;?>);
var change=parseFloat(received-(<?php echo $invoice->total_ttc;?>));
$('#change2').html(change.toFixed(2));
}
}
Expand All @@ -60,9 +60,13 @@ function reset()
}

function Validate(payment){
parent.$("#poslines").load("invoice.php?place=<?php echo $place;?>&action=valid&pay="+payment, function() {
parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
parent.$.colorbox.close();
parent.$("#poslines").load("invoice.php?place=<?php echo $place;?>&action=valid&pay="+payment, function(response, status, xhr) {
if(status == "error"){
alert(response);
}else{
parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
parent.$.colorbox.close();
}
});

}
Expand Down