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

Conflicts:
	htdocs/commande/class/commande.class.php
	htdocs/core/lib/security.lib.php
	htdocs/modulebuilder/template/myobject_card.php
This commit is contained in:
Laurent Destailleur 2018-10-30 14:47:39 +01:00
commit 68f6ebd0ff
15 changed files with 382 additions and 377 deletions

View File

@ -644,6 +644,11 @@ if (empty($reshook))
$msg = $arraydefaultmessage->content; $msg = $arraydefaultmessage->content;
} }
if (empty($labeltouse) || (int)$labeltouse === -1) {
//fallback on the old configuration.
setEventMessages('WarningMandatorySetupNotComplete', [], 'errors');
$error++;
}else{
$substitutionarray=getCommonSubstitutionArray($outputlangs, 0, null, $object); $substitutionarray=getCommonSubstitutionArray($outputlangs, 0, null, $object);
complete_substitutions_array($substitutionarray, $outputlangs, $object); complete_substitutions_array($substitutionarray, $outputlangs, $object);
$subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
@ -657,6 +662,9 @@ if (empty($reshook))
$error++; $error++;
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
}
} }
} }
else else
@ -718,6 +726,11 @@ if (empty($reshook))
$msg = $arraydefaultmessage->content; $msg = $arraydefaultmessage->content;
} }
if (empty($labeltouse) || (int)$labeltouse === -1) {
//fallback on the old configuration.
setEventMessages('WarningMandatorySetupNotComplete', [], 'errors');
$error++;
}else{
$substitutionarray=getCommonSubstitutionArray($outputlangs, 0, null, $object); $substitutionarray=getCommonSubstitutionArray($outputlangs, 0, null, $object);
complete_substitutions_array($substitutionarray, $outputlangs, $object); complete_substitutions_array($substitutionarray, $outputlangs, $object);
$subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs); $subjecttosend = make_substitutions($subject, $substitutionarray, $outputlangs);
@ -726,13 +739,16 @@ if (empty($reshook))
$moreinheader='X-Dolibarr-Info: send_an_email by adherents/card.php'."\r\n"; $moreinheader='X-Dolibarr-Info: send_an_email by adherents/card.php'."\r\n";
$result=$object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader); $result=$object->send_an_email($texttosend, $subjecttosend, array(), array(), array(), "", "", 0, -1, '', $moreinheader);
}
if ($result < 0) if ($result < 0)
{ {
$error++; $error++;
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
} }
}
}
else else
{ {
$error++; $error++;

View File

@ -40,7 +40,7 @@ $search_account=GETPOST('search_account','int');
$search_amount=GETPOST('search_amount','alpha'); $search_amount=GETPOST('search_amount','alpha');
$optioncss = GETPOST('optioncss','alpha'); $optioncss = GETPOST('optioncss','alpha');
$date_select=isset($_GET["date_select"])?$_GET["date_select"]:$_POST["date_select"]; $date_select=GETPOST("date_select",'alpha');
$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
$sortfield = GETPOST("sortfield",'alpha'); $sortfield = GETPOST("sortfield",'alpha');
@ -126,7 +126,8 @@ $sql.= " WHERE d.rowid = c.fk_adherent";
$sql.= " AND d.entity IN (".getEntity('adherent').")"; $sql.= " AND d.entity IN (".getEntity('adherent').")";
if (isset($date_select) && $date_select != '') if (isset($date_select) && $date_select != '')
{ {
$sql.= " AND c.dateadh LIKE '".$date_select."%'"; $sql.= " AND c.dateadh >= '".$date_select."-01-01 00:00:00'";
$sql.= " AND c.dateadh < '".($date_select+1)."-01-01 00:00:00'";
} }
if ($search_ref) if ($search_ref)
{ {

View File

@ -108,6 +108,9 @@ class Commande extends CommonOrder
*/ */
public $billed; // billed or not public $billed; // billed or not
/**
* @var int Draft Status of the order
*/
public $brouillon; public $brouillon;
public $cond_reglement_code; public $cond_reglement_code;
@ -274,7 +277,7 @@ class Commande extends CommonOrder
$mybool|=@include_once $dir.$file; $mybool|=@include_once $dir.$file;
} }
if (! $mybool) if ($mybool === false)
{ {
dol_print_error('',"Failed to include file ".$file); dol_print_error('',"Failed to include file ".$file);
return ''; return '';
@ -448,6 +451,7 @@ class Commande extends CommonOrder
{ {
$this->ref = $num; $this->ref = $num;
$this->statut = self::STATUS_VALIDATED; $this->statut = self::STATUS_VALIDATED;
$this->brouillon = 0;
} }
if (! $error) if (! $error)

View File

@ -93,11 +93,6 @@ $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') :
$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
// Security check
$fieldid = (! empty($ref) ? 'facnumber' : 'rowid');
if ($user->societe_id) $socid = $user->societe_id;
$result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid);
// Nombre de ligne pour choix de produit/service predefinis // Nombre de ligne pour choix de produit/service predefinis
$NBLINES = 4; $NBLINES = 4;
@ -118,6 +113,12 @@ $permissionnote = $user->rights->facture->creer; // Used by the include of actio
$permissiondellink=$user->rights->facture->creer; // Used by the include of actions_dellink.inc.php $permissiondellink=$user->rights->facture->creer; // Used by the include of actions_dellink.inc.php
$permissiontoedit = $user->rights->facture->creer; // Used by the include of actions_lineupdonw.inc.php $permissiontoedit = $user->rights->facture->creer; // Used by the include of actions_lineupdonw.inc.php
// Security check
$fieldid = (! empty($ref) ? 'facnumber' : 'rowid');
if ($user->societe_id) $socid = $user->societe_id;
$isdraft = (($object->statut == Facture::STATUS_DRAFT) ? 1 : 0);
$result = restrictedArea($user, 'facture', $id, '', '', 'fk_soc', $fieldid, $isdraft);
/* /*
* Actions * Actions
@ -178,7 +179,7 @@ if (empty($reshook))
} }
// Delete invoice // Delete invoice
else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->facture->supprimer) { else if ($action == 'confirm_delete' && $confirm == 'yes') {
$result = $object->fetch($id); $result = $object->fetch($id);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
@ -191,7 +192,10 @@ if (empty($reshook))
$qualified_for_stock_change = $object->hasProductsOrServices(1); $qualified_for_stock_change = $object->hasProductsOrServices(1);
} }
if ($object->is_erasable()) $isErasable=$object->is_erasable();
if (($user->rights->facture->supprimer && $isErasable > 0)
|| ($user->rights->facture->creer && $isErasable == 1))
{ {
$result = $object->delete($user, 0, $idwarehouse); $result = $object->delete($user, 0, $idwarehouse);
if ($result > 0) { if ($result > 0) {
@ -4847,9 +4851,9 @@ else if ($id > 0 || ! empty($ref))
} }
// Delete // Delete
if ($user->rights->facture->supprimer)
{
$isErasable = $object->is_erasable(); $isErasable = $object->is_erasable();
if ($user->rights->facture->supprimer || ($user->rights->facture->creer && $isErasable == 1)) // isErasable = 1 means draft with temporary ref (draft can always be deleted with no need of permissions)
{
//var_dump($isErasable); //var_dump($isErasable);
if ($isErasable == -4) { if ($isErasable == -4) {
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans("DisabledBecausePayments") . '">' . $langs->trans('Delete') . '</a></div>'; print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans("DisabledBecausePayments") . '">' . $langs->trans('Delete') . '</a></div>';

View File

@ -251,7 +251,7 @@ class Facture extends CommonInvoice
* If paid partially, $this->close_code can be: * If paid partially, $this->close_code can be:
* - CLOSECODE_DISCOUNTVAT * - CLOSECODE_DISCOUNTVAT
* - CLOSECODE_BADDEBT * - CLOSECODE_BADDEBT
* If paid completelly, this->close_code will be null * If paid completely, this->close_code will be null
*/ */
const STATUS_CLOSED = 2; const STATUS_CLOSED = 2;
@ -2442,7 +2442,7 @@ class Facture extends CommonInvoice
} }
} }
// Set new ref and define current statut // Set new ref and define current status
if (! $error) if (! $error)
{ {
$this->ref = $num; $this->ref = $num;
@ -4950,7 +4950,7 @@ class FactureLigne extends CommonInvoiceLine
if (is_null($this->fk_prev_id) || empty($this->fk_prev_id) || $this->fk_prev_id == "") { if (is_null($this->fk_prev_id) || empty($this->fk_prev_id) || $this->fk_prev_id == "") {
return 0; return 0;
} else { } else {
// If invoice is a not a situation invoice, this->fk_prev_id is used for something else // If invoice is not a situation invoice, this->fk_prev_id is used for something else
$tmpinvoice=new Facture($this->db); $tmpinvoice=new Facture($this->db);
$tmpinvoice->fetch($invoiceid); $tmpinvoice->fetch($invoiceid);
if ($tmpinvoice->type != Facture::TYPE_SITUATION) return 0; if ($tmpinvoice->type != Facture::TYPE_SITUATION) return 0;

View File

@ -329,12 +329,13 @@ abstract class CommonInvoice extends CommonObject
/** /**
* Return if an invoice can be deleted * Return if an invoice can be deleted
* Rule is: * Rule is:
* If invoice is draft and has a temporary ref -> yes * If invoice is draft and has a temporary ref -> yes (1)
* If hidden option INVOICE_CAN_NEVER_BE_REMOVED is on -> no (0) * If hidden option INVOICE_CAN_NEVER_BE_REMOVED is on -> no (0)
* If invoice is dispatched in bookkeeping -> no (-1) * If invoice is dispatched in bookkeeping -> no (-1)
* If invoice has a definitive ref, is not last and INVOICE_CAN_ALWAYS_BE_REMOVED off -> no (-2) * If invoice has a definitive ref, is not last and INVOICE_CAN_ALWAYS_BE_REMOVED off -> no (-2)
* If invoice not last in a cycle -> no (-3) * If invoice not last in a cycle -> no (-3)
* If there is payment -> no (-4) * If there is payment -> no (-4)
* Otherwise -> yes (2)
* *
* @return int <=0 if no, >0 if yes * @return int <=0 if no, >0 if yes
*/ */
@ -383,7 +384,7 @@ abstract class CommonInvoice extends CommonObject
// Test if there is at least one payment. If yes, refuse to delete. // Test if there is at least one payment. If yes, refuse to delete.
if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $this->getSommePaiement() > 0) return -4; if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $this->getSommePaiement() > 0) return -4;
return 1; return 2;
} }
/** /**

View File

@ -6580,7 +6580,7 @@ function get_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb
* @see dol_print_error * @see dol_print_error
* @see dol_htmloutput_mesg * @see dol_htmloutput_mesg
*/ */
function get_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0) function get_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
{ {
return get_htmloutput_mesg($mesgstring, $mesgarray,'error',$keepembedded); return get_htmloutput_mesg($mesgstring, $mesgarray,'error',$keepembedded);
} }
@ -6598,7 +6598,7 @@ function get_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0)
* @see dol_htmloutput_errors * @see dol_htmloutput_errors
* @see setEventMessages * @see setEventMessages
*/ */
function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepembedded=0) function dol_htmloutput_mesg($mesgstring = '',$mesgarray = array(), $style = 'ok', $keepembedded=0)
{ {
if (empty($mesgstring) && (! is_array($mesgarray) || count($mesgarray) == 0)) return; if (empty($mesgstring) && (! is_array($mesgarray) || count($mesgarray) == 0)) return;
@ -6652,7 +6652,7 @@ function dol_htmloutput_mesg($mesgstring='',$mesgarray='', $style='ok', $keepemb
* @see dol_print_error * @see dol_print_error
* @see dol_htmloutput_mesg * @see dol_htmloutput_mesg
*/ */
function dol_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0) function dol_htmloutput_errors($mesgstring='', $mesgarray=array(), $keepembedded=0)
{ {
dol_htmloutput_mesg($mesgstring, $mesgarray, 'error', $keepembedded); dol_htmloutput_mesg($mesgstring, $mesgarray, 'error', $keepembedded);
} }

View File

@ -174,10 +174,11 @@ function dol_verifyHash($chain, $hash, $type='0')
* @param string $feature2 Feature to check, second level of permission (optional). Can be a 'or' check with 'level1|level2'. * @param string $feature2 Feature to check, second level of permission (optional). Can be a 'or' check with 'level1|level2'.
* @param string $dbt_keyfield Field name for socid foreign key if not fk_soc. Not used if objectid is null (optional) * @param string $dbt_keyfield Field name for socid foreign key if not fk_soc. Not used if objectid is null (optional)
* @param string $dbt_select Field name for select if not rowid. Not used if objectid is null (optional) * @param string $dbt_select Field name for select if not rowid. Not used if objectid is null (optional)
* @param int $isdraft 1=The object with id=$objectid is a draft
* @return int Always 1, die process if not allowed * @return int Always 1, die process if not allowed
* @see dol_check_secure_access_document * @see dol_check_secure_access_document
*/ */
function restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid') function restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
{ {
global $db, $conf; global $db, $conf;
global $hookmanager; global $hookmanager;
@ -275,9 +276,9 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu
if (! $readok) accessforbidden(); if (! $readok) accessforbidden();
//print "Read access is ok"; //print "Read access is ok";
// Check write permission from module // Check write permission from module (we need to know write permission to create but also to delete drafts record)
$createok=1; $nbko=0; $createok=1; $nbko=0;
if (GETPOST('action','aZ09') == 'create') if (GETPOST('action','aZ09') == 'create' || ((GETPOST("action","aZ09") == 'confirm_delete' && GETPOST("confirm","aZ09") == 'yes') || GETPOST("action","aZ09") == 'delete'))
{ {
foreach ($featuresarray as $feature) foreach ($featuresarray as $feature)
{ {
@ -327,7 +328,7 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu
// If a or and at least one ok // If a or and at least one ok
if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) $createok=1; if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) $createok=1;
if (! $createok) accessforbidden(); if (GETPOST('action','aZ09') == 'create' && ! $createok) accessforbidden();
//print "Write access is ok"; //print "Write access is ok";
} }
@ -382,7 +383,7 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu
{ {
if (! $user->rights->salaries->delete) $deleteok=0; if (! $user->rights->salaries->delete) $deleteok=0;
} }
else if (! empty($feature2)) // This should be used for future changes else if (! empty($feature2)) // This should be used for permissions on 2 levels
{ {
foreach($feature2 as $subfeature) foreach($feature2 as $subfeature)
{ {
@ -390,7 +391,7 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu
else { $deleteok=1; break; } // For bypass the second test if the first is ok else { $deleteok=1; break; } // For bypass the second test if the first is ok
} }
} }
else if (! empty($feature)) // This is for old permissions else if (! empty($feature)) // This is used for permissions on 1 level
{ {
//print '<br>feature='.$feature.' creer='.$user->rights->$feature->supprimer.' write='.$user->rights->$feature->delete; //print '<br>feature='.$feature.' creer='.$user->rights->$feature->supprimer.' write='.$user->rights->$feature->delete;
if (empty($user->rights->$feature->supprimer) if (empty($user->rights->$feature->supprimer)
@ -402,7 +403,7 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu
// If a or and at least one ok // If a or and at least one ok
if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) $deleteok=1; if (preg_match('/\|/', $features) && $nbko < count($featuresarray)) $deleteok=1;
if (! $deleteok) accessforbidden(); if (! $deleteok && ! ($isdraft && $createok)) accessforbidden();
//print "Delete access is ok"; //print "Delete access is ok";
} }

View File

@ -808,43 +808,6 @@ class pdf_typhon extends ModelePDFDeliveryOrder
$posy+=2; $posy+=2;
// Add list of linked orders on shipment
// Currently not supported by pdf_writeLinkedObjects, link for delivery to order is done through shipment)
if ($object->origin == 'expedition' || $object->origin == 'shipping')
{
$Yoff=$posy-5;
include_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
$shipment = new Expedition($this->db);
$shipment->fetch($object->origin_id);
$origin = $shipment->origin;
$origin_id = $shipment->origin_id;
if ($conf->$origin->enabled)
{
$outputlangs->load('orders');
$classname = ucfirst($origin);
$linkedobject = new $classname($this->db);
$result=$linkedobject->fetch($origin_id);
if ($result >= 0)
{
$pdf->SetFont('','', $default_font_size - 2);
$text=$linkedobject->ref;
if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')';
$Yoff = $Yoff+8;
$pdf->SetXY($this->page_largeur - $this->marge_droite - 100,$Yoff);
$pdf->MultiCell(100, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R');
$Yoff = $Yoff+3;
$pdf->SetXY($this->page_largeur - $this->marge_droite - 60,$Yoff);
$pdf->MultiCell(60, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date,"day",false,$outputlangs,true), 0, 'R');
}
}
$posy=$Yoff;
}
// Show list of linked objects // Show list of linked objects
$posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size); $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size);

View File

@ -73,11 +73,6 @@ $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (!
$hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
$hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
// Security check
$socid='';
if (! empty($user->societe_id)) $socid=$user->societe_id;
$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager->initHooks(array('invoicesuppliercard','globalcard')); $hookmanager->initHooks(array('invoicesuppliercard','globalcard'));
@ -96,6 +91,12 @@ if ($id > 0 || ! empty($ref))
if ($ret < 0) dol_print_error($db,$object->error); if ($ret < 0) dol_print_error($db,$object->error);
} }
// Security check
$socid='';
if (! empty($user->societe_id)) $socid=$user->societe_id;
$isdraft = (($object->statut == FactureFournisseur::STATUS_DRAFT) ? 1 : 0);
$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture', 'fk_soc', 'rowid', $isdraft);
$permissionnote=$user->rights->fournisseur->facture->creer; // Used by the include of actions_setnotes.inc.php $permissionnote=$user->rights->fournisseur->facture->creer; // Used by the include of actions_setnotes.inc.php
$permissiondellink=$user->rights->fournisseur->facture->creer; // Used by the include of actions_dellink.inc.php $permissiondellink=$user->rights->fournisseur->facture->creer; // Used by the include of actions_dellink.inc.php
$permissionedit=$user->rights->fournisseur->facture->creer; // Used by the include of actions_lineupdown.inc.php $permissionedit=$user->rights->fournisseur->facture->creer; // Used by the include of actions_lineupdown.inc.php
@ -219,10 +220,16 @@ if (empty($reshook))
} }
} }
elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer) elseif ($action == 'confirm_delete' && $confirm == 'yes')
{ {
$object->fetch($id); $object->fetch($id);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
$isErasable=$object->is_erasable();
if (($user->rights->fournisseur->facture->supprimer && $isErasable > 0)
|| ($user->rights->fournisseur->facture->creer && $isErasable == 1))
{
$result=$object->delete($user); $result=$object->delete($user);
if ($result > 0) if ($result > 0)
{ {
@ -234,6 +241,7 @@ if (empty($reshook))
setEventMessages($object->error, $object->errors, 'errors'); setEventMessages($object->error, $object->errors, 'errors');
} }
} }
}
// Remove a product line // Remove a product line
else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer) else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer)
@ -3114,9 +3122,9 @@ else
} }
// Delete // Delete
if ($action != 'confirm_edit' && $user->rights->fournisseur->facture->supprimer)
{
$isErasable=$object->is_erasable(); $isErasable=$object->is_erasable();
if ($action != 'confirm_edit' && ($user->rights->fournisseur->facture->supprimer || ($user->rights->fournisseur->facture->creer && $isErasable == 1))) // isErasable = 1 means draft with temporary ref (draft can always be deleted with no need of permissions)
{
//var_dump($isErasable); //var_dump($isErasable);
if ($isErasable == -4) { if ($isErasable == -4) {
print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans("DisabledBecausePayments") . '">' . $langs->trans('Delete') . '</a></div>'; print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="' . $langs->trans("DisabledBecausePayments") . '">' . $langs->trans('Delete') . '</a></div>';

View File

@ -89,6 +89,7 @@ ErrorFileIsInfectedWithAVirus=The antivirus program was not able to validate the
ErrorSpecialCharNotAllowedForField=Special characters are not allowed for field "%s" ErrorSpecialCharNotAllowedForField=Special characters are not allowed for field "%s"
ErrorNumRefModel=A reference exists into database (%s) and is not compatible with this numbering rule. Remove record or renamed reference to activate this module. ErrorNumRefModel=A reference exists into database (%s) and is not compatible with this numbering rule. Remove record or renamed reference to activate this module.
ErrorQtyTooLowForThisSupplier=Quantity too low for this vendor or no price defined on this product for this supplier ErrorQtyTooLowForThisSupplier=Quantity too low for this vendor or no price defined on this product for this supplier
ErrorOrdersNotCreatedQtyTooLow=Some orders haven't been created beacuse of too low quantity
ErrorModuleSetupNotComplete=Setup of module looks to be uncomplete. Go on Home - Setup - Modules to complete. ErrorModuleSetupNotComplete=Setup of module looks to be uncomplete. Go on Home - Setup - Modules to complete.
ErrorBadMask=Error on mask ErrorBadMask=Error on mask
ErrorBadMaskFailedToLocatePosOfSequence=Error, mask without sequence number ErrorBadMaskFailedToLocatePosOfSequence=Error, mask without sequence number

View File

@ -340,19 +340,19 @@ if ($action == 'create')
// Accountancy_account_capital // Accountancy_account_capital
print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>'; print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("LoanAccountancyCapitalCode").'</td>';
print '<td>'; print '<td>';
print $formaccounting->select_account($object->accountancy_account_capital, 'accountancy_account_capital', 1, '', 0, 1); print $formaccounting->select_account(GETPOST('accountancy_account_capital')?GETPOST('accountancy_account_capital'):$conf->global->LOAN_ACCOUNTING_ACCOUNT_CAPITAL, 'accountancy_account_capital', 1, '', 1, 1);
print '</td></tr>'; print '</td></tr>';
// Accountancy_account_insurance // Accountancy_account_insurance
print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInsuranceCode").'</td>';
print '<td>'; print '<td>';
print $formaccounting->select_account($object->accountancy_account_insurance, 'accountancy_account_insurance', 1, '', 0, 1); print $formaccounting->select_account(GETPOST('accountancy_account_insurance')?GETPOST('accountancy_account_insurance'):$conf->global->LOAN_ACCOUNTING_ACCOUNT_INSURANCE, 'accountancy_account_insurance', 1, '', 1, 1);
print '</td></tr>'; print '</td></tr>';
// Accountancy_account_interest // Accountancy_account_interest
print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("LoanAccountancyInterestCode").'</td>';
print '<td>'; print '<td>';
print $formaccounting->select_account($object->accountancy_account_interest, 'accountancy_account_interest', 1, '', 0, 1); print $formaccounting->select_account(GETPOST('accountancy_account_interest')?GETPOST('accountancy_account_interest'):$conf->global->LOAN_ACCOUNTING_ACCOUNT_INTEREST, 'accountancy_account_interest', 1, '', 1, 1);
print '</td></tr>'; print '</td></tr>';
} }
else // For external software else // For external software

View File

@ -99,7 +99,8 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be inclu
// Security check - Protection if external user // Security check - Protection if external user
//if ($user->societe_id > 0) access_forbidden(); //if ($user->societe_id > 0) access_forbidden();
//if ($user->societe_id > 0) $socid = $user->societe_id; //if ($user->societe_id > 0) $socid = $user->societe_id;
//$result = restrictedArea($user, 'mymodule', $object->id); //$isdraft = (($object->statut == MyObject::STATUS_DRAFT) ? 1 : 0);
//$result = restrictedArea($user, 'mymodule', $object->id, '', '', 'fk_soc', 'rowid', $isdraft);
/* /*

View File

@ -112,12 +112,15 @@ if ($action == 'order' && isset($_POST['valid']))
{ {
$linecount = GETPOST('linecount', 'int'); $linecount = GETPOST('linecount', 'int');
$box = 0; $box = 0;
$errorQty = 0;
unset($_POST['linecount']); unset($_POST['linecount']);
if ($linecount > 0) if ($linecount > 0)
{ {
$db->begin(); $db->begin();
$suppliers = array(); $suppliers = array();
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
$productsupplier = new ProductFournisseur($db);
for ($i = 0; $i < $linecount; $i++) for ($i = 0; $i < $linecount; $i++)
{ {
if (GETPOST('choose' . $i, 'alpha') === 'on' && GETPOST('fourn' . $i, 'int') > 0) if (GETPOST('choose' . $i, 'alpha') === 'on' && GETPOST('fourn' . $i, 'int') > 0)
@ -127,13 +130,9 @@ if ($action == 'order' && isset($_POST['valid']))
$supplierpriceid = GETPOST('fourn'.$i, 'int'); $supplierpriceid = GETPOST('fourn'.$i, 'int');
//get all the parameters needed to create a line //get all the parameters needed to create a line
$qty = GETPOST('tobuy'.$i, 'int'); $qty = GETPOST('tobuy'.$i, 'int');
//$desc = GETPOST('desc'.$i, 'alpha'); $idprod=$productsupplier->get_buyprice($supplierpriceid, $qty);
$sql = 'SELECT fk_product, fk_soc, ref_fourn'; $res=$productsupplier->fetch($idprod);
$sql .= ', tva_tx, unitprice, remise_percent FROM '; if ($res && $idprod > 0)
$sql .= MAIN_DB_PREFIX . 'product_fournisseur_price';
$sql .= ' WHERE rowid = ' . $supplierpriceid;
$resql = $db->query($sql);
if ($resql && $db->num_rows($resql) > 0)
{ {
if ($qty) if ($qty)
{ {
@ -141,33 +140,37 @@ if ($action == 'order' && isset($_POST['valid']))
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
$line = new CommandeFournisseurLigne($db); $line = new CommandeFournisseurLigne($db);
$line->qty = $qty; $line->qty = $qty;
$line->fk_product = $obj->fk_product; $line->fk_product = $idprod;
$product = new Product($db); //$product = new Product($db);
$product->fetch($obj->fk_product); //$product->fetch($obj->fk_product);
if (! empty($conf->global->MAIN_MULTILANGS)) if (! empty($conf->global->MAIN_MULTILANGS))
{ {
$product->getMultiLangs(); $productsupplier->getMultiLangs();
} }
$line->desc = $product->description; $line->desc = $productsupplier->description;
if (! empty($conf->global->MAIN_MULTILANGS)) if (! empty($conf->global->MAIN_MULTILANGS))
{ {
// TODO Get desc in language of thirdparty // TODO Get desc in language of thirdparty
} }
$line->tva_tx = $obj->tva_tx; $line->tva_tx = $productsupplier->vatrate_supplier;
$line->subprice = $obj->unitprice; $line->subprice = $productsupplier->fourn_pu;
$line->total_ht = $obj->unitprice * $qty; $line->total_ht = $productsupplier->fourn_pu * $qty;
$tva = $line->tva_tx / 100; $tva = $line->tva_tx / 100;
$line->total_tva = $line->total_ht * $tva; $line->total_tva = $line->total_ht * $tva;
$line->total_ttc = $line->total_ht + $line->total_tva; $line->total_ttc = $line->total_ht + $line->total_tva;
$line->remise_percent = $obj->remise_percent; $line->remise_percent = $productsupplier->remise_percent;
$line->ref_fourn = $obj->ref_fourn; $line->ref_fourn = $productsupplier->ref_supplier;
$line->type = $product->type; $line->type = $productsupplier->type;
$line->fk_unit = $product->fk_unit; $line->fk_unit = $productsupplier->fk_unit;
$suppliers[$obj->fk_soc]['lines'][] = $line; $suppliers[$productsupplier->fourn_socid]['lines'][] = $line;
} }
} }
elseif ($idprod == -1)
{
$errorQty++;
}
else else
{ {
$error=$db->lasterror(); $error=$db->lasterror();
@ -248,6 +251,8 @@ if ($action == 'order' && isset($_POST['valid']))
} }
} }
if($errorQty) setEventMessages($langs->trans('ErrorOrdersNotCreatedQtyTooLow'), null, 'warnings');
if (! $fail && $id) if (! $fail && $id)
{ {
$db->commit(); $db->commit();

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2013 Jean-François Ferry <jfefe@aternatik.fr> /* Copyright (C) 2013-2018 Jean-François Ferry <hello+jf@librethic.io>
* Copyright (C) 2016 Gilles Poirier <glgpoirier@gmail.com> * Copyright (C) 2016 Gilles Poirier <glgpoirier@gmail.com>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -90,7 +90,7 @@ if ($action == 'add_element_resource' && ! $cancel)
else else
{ {
$objstat = fetchObjectByElement($element_id, $element); $objstat = fetchObjectByElement($element_id, $element);
$objstat->element = $element; // For externals module, we need to keep @xx
$res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory); $res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory);
} }
if (! $error && $res > 0) if (! $error && $res > 0)