Allow negative bills
This commit is contained in:
parent
48a0c447b4
commit
ed81d35e38
@ -41,6 +41,20 @@ $idline = GETPOST('idline');
|
|||||||
$desc = GETPOST('desc', 'alpha');
|
$desc = GETPOST('desc', 'alpha');
|
||||||
$pay = GETPOST('pay');
|
$pay = GETPOST('pay');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abort invoice creationg with a given error message
|
||||||
|
*
|
||||||
|
* @param string $message Message explaining the error to the user
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function fail($message)
|
||||||
|
{
|
||||||
|
header($_SERVER['SERVER_PROTOCOL'] . ' 500 Internal Server Error', true, 500);
|
||||||
|
die($message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$placeid = 0; // $placeid is id of invoice
|
$placeid = 0; // $placeid is id of invoice
|
||||||
|
|
||||||
$invoice = new Facture($db);
|
$invoice = new Facture($db);
|
||||||
@ -62,6 +76,26 @@ if ($action == 'valid' && $user->rights->facture->creer)
|
|||||||
|
|
||||||
$invoice = new Facture($db);
|
$invoice = new Facture($db);
|
||||||
$invoice->fetch($placeid);
|
$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);
|
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);
|
else $invoice->validate($user);
|
||||||
|
|||||||
@ -66,7 +66,7 @@ $langs->loadLangs(array("main", "bills", "cashdesk"));
|
|||||||
$('#change1').html(parseFloat(received).toFixed(2));
|
$('#change1').html(parseFloat(received).toFixed(2));
|
||||||
if (parseFloat(received)><?php echo $invoice->total_ttc;?>)
|
if (parseFloat(received)><?php echo $invoice->total_ttc;?>)
|
||||||
{
|
{
|
||||||
var change=parseFloat(parseFloat(received)-<?php echo $invoice->total_ttc;?>);
|
var change=parseFloat(parseFloat(received)-(<?php echo $invoice->total_ttc;?>));
|
||||||
$('#change2').html(change.toFixed(2));
|
$('#change2').html(change.toFixed(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,10 +79,14 @@ $langs->loadLangs(array("main", "bills", "cashdesk"));
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Validate(payment){
|
function Validate(payment){
|
||||||
parent.$("#poslines").load("invoice.php?place=<?php echo $place;?>&action=valid&pay="+payment, function() {
|
parent.$("#poslines").load("invoice.php?place=<?php echo $place;?>&action=valid&pay="+payment, function(response, status, xhr) {
|
||||||
parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
|
if(status == "error"){
|
||||||
parent.$.colorbox.close();
|
alert(response);
|
||||||
});
|
}else{
|
||||||
|
parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
|
||||||
|
parent.$.colorbox.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user