Merge branch 'develop' of git@github.com:Dolibarr/dolibarr.git into develop

This commit is contained in:
Laurent Destailleur 2019-04-01 18:44:16 +02:00
commit 2956bbe734
4 changed files with 112 additions and 3 deletions

View File

@ -6773,8 +6773,6 @@ class Form
return $resultyesno;
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
* Return list of export templates

View File

@ -9,6 +9,7 @@
* Copyright (C) 2006 Marc Barilley/Ocebo <marc@ocebo.com>
* Copyright (C) 2007 Franky Van Liedekerke <franky.van.liedekerker@telenet.be>
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2019 Thibault FOUCART <support@ptibogxiv.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -1232,4 +1233,44 @@ class FormOther
dol_print_error($this->db);
}
}
/**
* Return an html string with a select combo box to choose yes or no
*
* @param string $htmlname Name of html select field
* @param string $value Pre-selected value
* @param int $option 0 return automatic/manual, 1 return 1/0
* @param bool $disabled true or false
* @param int $useempty 1=Add empty line
* @return string See option
*/
public function selectAutoManual($htmlname, $value = '', $option = 0, $disabled = false, $useempty = 0)
{
global $langs;
$automatic="automatic"; $manual="manual";
if ($option)
{
$automatic="1";
$manual="0";
}
$disabled = ($disabled ? ' disabled' : '');
$resultautomanual = '<select class="flat width100" id="'.$htmlname.'" name="'.$htmlname.'"'.$disabled.'>'."\n";
if ($useempty) $resultautomanual .= '<option value="-1"'.(($value < 0)?' selected':'').'>&nbsp;</option>'."\n";
if (("$value" == 'automatic') || ($value == 1))
{
$resultautomanual .= '<option value="'.$automatic.'" selected>'.$langs->trans("Automatic").'</option>'."\n";
$resultautomanual .= '<option value="'.$manual.'">'.$langs->trans("Manual").'</option>'."\n";
}
else
{
$selected=(($useempty && $value != '0' && $value != 'manual')?'':' selected');
$resultautomanual .= '<option value="'.$automatic.'">'.$langs->trans("Automatic").'</option>'."\n";
$resultautomanual .= '<option value="'.$manual.'"'.$selected.'>'.$langs->trans("Manual").'</option>'."\n";
}
$resultautomanual .= '</select>'."\n";
return $resultautomanual;
}
}

View File

@ -14,6 +14,7 @@
* Copyright (C) 2014-2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2018-2019 Frédéric France <frederic.france@netlogic.fr>
* Copyright (C) 2019 Thibault Foucart <support@ptibogxiv.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -5211,6 +5212,40 @@ function yn($yesno, $case = 1, $color = 0)
return $result;
}
/**
* Return automatic or manual in current language
*
* @param string $automaticmanual Value to test (1, 'automatic', 'true' or 0, 'manual', 'false')
* @param integer $case 1=Yes/No, 0=yes/no, 2=Disabled checkbox, 3=Disabled checkbox + Automatic/Manual
* @param int $color 0=texte only, 1=Text is formated with a color font style ('ok' or 'error'), 2=Text is formated with 'ok' color.
* @return string HTML string
*/
function am($automaticmanual, $case = 1, $color = 0)
{
global $langs;
$result='unknown'; $classname='';
if ($automaticmanual == 1 || strtolower($automaticmanual) == 'automatic' || strtolower($automaticmanual) == 'true') // A mettre avant test sur no a cause du == 0
{
$result=$langs->trans('automatic');
if ($case == 1 || $case == 3) $result=$langs->trans("Automatic");
if ($case == 2) $result='<input type="checkbox" value="1" checked disabled>';
if ($case == 3) $result='<input type="checkbox" value="1" checked disabled> '.$result;
$classname='ok';
}
elseif ($yesno == 0 || strtolower($automaticmanual) == 'manual' || strtolower($automaticmanual) == 'false')
{
$result=$langs->trans("manual");
if ($case == 1 || $case == 3) $result=$langs->trans("Manual");
if ($case == 2) $result='<input type="checkbox" value="0" disabled>';
if ($case == 3) $result='<input type="checkbox" value="0" disabled> '.$result;
if ($color == 2) $classname='ok';
else $classname='error';
}
if ($color) return '<font class="'.$classname.'">'.$result.'</font>';
return $result;
}
/**
* Return a path to have a the directory according to object where files are stored.

View File

@ -41,10 +41,25 @@ $langs->loadLangs(array("bills", "cashdesk"));
$id = GETPOST('id', 'int');
$action = GETPOST('action', 'alpha');
$idproduct = GETPOST('idproduct', 'int');
$place = (GETPOST('place', 'int') > 0 ? GETPOST('place', 'int') : 0); // $place is id of table for Ba or Restaurant
$posnb = (GETPOST('posnb', 'int') > 0 ? GETPOST('posnb', 'int') : 0); // $posnb is id of POS
/**
* 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
$number = GETPOST('number', 'alpha');
$idline = GETPOST('idline', 'int');
$desc = GETPOST('desc', 'alpha');
@ -100,6 +115,26 @@ if ($action == 'valid' && $user->rights->facture->creer)
$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) && $conf->global->CASHDESK_NO_DECREASE_STOCK != "1")
{