diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 51ef317e917..20780e72508 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -609,6 +609,7 @@ class BookKeeping extends CommonObject } } + /** * Load object in memory from the database * @@ -1093,7 +1094,6 @@ class BookKeeping extends CommonObject * @param User $user User that deletes * @param bool $notrigger false=launch triggers after, true=disable triggers * @param string $mode Mode - * * @return int <0 if KO, >0 if OK */ public function delete(User $user, $notrigger = false, $mode='') { @@ -1761,4 +1761,4 @@ class BookKeepingLine public $code_journal; public $journal_label; public $piece_num; -} \ No newline at end of file +} diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index fef8082901c..30d91294c86 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1359,10 +1359,10 @@ class Commande extends CommonOrder $this->line->vat_src_code=$vat_src_code; $this->line->tva_tx=$txtva; - $this->line->localtax1_tx=$txlocaltax1; - $this->line->localtax2_tx=$txlocaltax2; - $this->line->localtax1_type = $localtaxes_type[0]; - $this->line->localtax2_type = $localtaxes_type[2]; + $this->line->localtax1_tx=$localtaxes_type[1]; + $this->line->localtax2_tx=$localtaxes_type[3]; + $this->line->localtax1_type=$localtaxes_type[0]; + $this->line->localtax2_type=$localtaxes_type[2]; $this->line->fk_product=$fk_product; $this->line->product_type=$product_type; $this->line->fk_remise_except=$fk_remise_except; diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 513c6854eb8..5ab62bf5337 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -594,6 +594,7 @@ if ($resql) $i = 0; print '
'."\n"; + if ($optioncss != '') print ''; print ''; print ''; @@ -1253,10 +1254,10 @@ if ($resql) // Status if (! empty($arrayfields['f.fk_statut']['checked'])) { - print ''; - print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$paiement,$obj->type); - print ""; - if (! $i) $totalarray['nbfield']++; + print ''; + print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$paiement,$obj->type); + print ""; + if (! $i) $totalarray['nbfield']++; } // Action column diff --git a/htdocs/compta/paiement/class/cpaiement.class.php b/htdocs/compta/paiement/class/cpaiement.class.php index d6031ae1685..b089cac6aab 100644 --- a/htdocs/compta/paiement/class/cpaiement.class.php +++ b/htdocs/compta/paiement/class/cpaiement.class.php @@ -42,7 +42,7 @@ class Cpaiement /** */ - + public $code; public $libelle; public $type; @@ -52,7 +52,7 @@ class Cpaiement /** */ - + /** * Constructor @@ -79,7 +79,7 @@ class Cpaiement $error = 0; // Clean parameters - + if (isset($this->code)) { $this->code = trim($this->code); } @@ -99,14 +99,14 @@ class Cpaiement $this->module = trim($this->module); } - + // Check parameters // Put here code to add control on parameters values // Insert request $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; - + $sql.= 'id,'; $sql.= 'code,'; $sql.= 'libelle,'; @@ -115,9 +115,9 @@ class Cpaiement $sql.= 'accountancy_code,'; $sql.= 'module'; - + $sql .= ') VALUES ('; - + $sql .= ' '.(! isset($this->id)?'NULL':$this->id).','; $sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").','; $sql .= ' '.(! isset($this->libelle)?'NULL':"'".$this->db->escape($this->libelle)."'").','; @@ -126,7 +126,7 @@ class Cpaiement $sql .= ' '.(! isset($this->accountancy_code)?'NULL':"'".$this->db->escape($this->accountancy_code)."'").','; $sql .= ' '.(! isset($this->module)?'NULL':"'".$this->db->escape($this->module)."'"); - + $sql .= ')'; $this->db->begin(); @@ -198,7 +198,7 @@ class Cpaiement $obj = $this->db->fetch_object($resql); $this->id = $obj->id; - + $this->code = $obj->code; $this->libelle = $obj->libelle; $this->type = $obj->type; @@ -206,7 +206,7 @@ class Cpaiement $this->accountancy_code = $obj->accountancy_code; $this->module = $obj->module; - + } $this->db->free($resql); @@ -238,7 +238,7 @@ class Cpaiement dol_syslog(__METHOD__, LOG_DEBUG); // Clean parameters - + if (isset($this->code)) { $this->code = trim($this->code); } @@ -258,7 +258,7 @@ class Cpaiement $this->module = trim($this->module); } - + // Check parameters // Put here code to add a control on parameters values @@ -356,8 +356,8 @@ class Cpaiement return 1; } } - - + + /** * Initialise object with example values * Id must be 0 if object instance is a specimen @@ -367,7 +367,7 @@ class Cpaiement public function initAsSpecimen() { $this->id = 0; - + $this->code = ''; $this->libelle = ''; $this->type = ''; @@ -375,7 +375,7 @@ class Cpaiement $this->accountancy_code = ''; $this->module = ''; - + } } diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index 630197cfc78..0ab82a7cae3 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -67,7 +67,7 @@ if ($action == 'reopen' && $user->rights->tax->charges->creer) { if ($object->paye) { $result = $object->set_unpaid($user); - if ($result > 0) + if ($result > 0) { header('Location: ' . $_SERVER["PHP_SELF"] . '?id=' . $id); exit(); @@ -350,7 +350,7 @@ if ($action == 'create') print ''.$langs->trans("Project").''; $numproject=$formproject->select_projects(-1, $projectid,'fk_project',0,0,1,1); - + print ''; } @@ -405,7 +405,7 @@ if ($id > 0) $head=tax_prepare_head($object); $totalpaye = $object->getSommePaiement(); - + // Clone confirmation if ($action === 'clone') { @@ -473,21 +473,21 @@ if ($id > 0) $morehtmlref.=''; } } - } + } $morehtmlref.=''; - + $linkback = '' . $langs->trans("BackToList") . ''; - + $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status - + dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', $morehtmlright); - + print '
'; print '
'; print '
'; - + print ''; - + // Type print '"; print ""; @@ -588,7 +588,7 @@ if ($id > 0) if ($resql) { $totalpaye = 0; - + $num = $db->num_rows($resql); $i = 0; $total = 0; print '
'.$langs->trans("Type")."".$object->type_libelle."
'; @@ -598,14 +598,14 @@ if ($id > 0) print ''; print ''; print ''; - + $var=true; if ($num > 0) { while ($i < $num) { $objp = $db->fetch_object($resql); - + print "'; print '\n"; @@ -619,18 +619,18 @@ if ($id > 0) } else { - + print ''; } - + //if ($object->status == ChargeSociales::STATUS_DRAFT) //{ print "\n"; print "\n"; - + $resteapayer = $object->amount - $totalpaye; $cssforamountpaymentcomplete = 'amountpaymentcomplete'; - + print ""; print '\n"; //} @@ -640,12 +640,12 @@ if ($id > 0) else { dol_print_error($db); - } - + } + print ''; print ''; print ''; - + print '
'; dol_fiche_end(); diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 608f5614cd8..e08e10a0966 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -228,7 +228,7 @@ class Contrat extends CommonObject */ function active_line($user, $line_id, $date, $date_end='', $comment='') { - $this->lines[$this->lines_id_index_mapper[$line_id]]->active_line($user, $date, $date_end, $comment); + return $this->lines[$this->lines_id_index_mapper[$line_id]]->active_line($user, $date, $date_end, $comment); } @@ -243,7 +243,7 @@ class Contrat extends CommonObject */ function close_line($user, $line_id, $date_end, $comment='') { - $this->lines[$this->lines_id_index_mapper[$line_id]]->close_line($user, $date_end, $comment); + return $this->lines[$this->lines_id_index_mapper[$line_id]]->close_line($user, $date_end, $comment); } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1339512b3af..96de26be956 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -599,48 +599,64 @@ abstract class CommonObject } $datecreate = dol_now(); - - $this->db->begin(); - - // Insertion dans la base - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; - $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; - $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; - $sql.= "'".$this->db->idate($datecreate)."'"; - $sql.= ", 4, ". $id_type_contact; - $sql.= ")"; - - $resql=$this->db->query($sql); - if ($resql) - { - if (! $notrigger) - { - $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); - if ($result < 0) + + // Socpeople must have already been added by some a trigger, then we have to check it to avoid DB_ERROR_RECORD_ALREADY_EXISTS error + $TListeContacts=$this->liste_contact(-1, $source); + $already_added=false; + if(!empty($TListeContacts)) { + foreach($TListeContacts as $array_contact) { + if($array_contact['status'] == 4 && $array_contact['id'] == $fk_socpeople && $array_contact['fk_c_type_contact'] == $id_type_contact) { + $already_added=true; + break; + } + } + } + + if(!$already_added) { + + $this->db->begin(); + + // Insertion dans la base + $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; + $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; + $sql.= " VALUES (".$this->id.", ".$fk_socpeople." , " ; + $sql.= "'".$this->db->idate($datecreate)."'"; + $sql.= ", 4, ". $id_type_contact; + $sql.= ")"; + + $resql=$this->db->query($sql); + if ($resql) + { + if (! $notrigger) { + $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + } + + $this->db->commit(); + return 1; + } + else + { + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $this->error=$this->db->errno(); + $this->db->rollback(); + echo 'err rollback'; + return -2; + } + else + { + $this->error=$this->db->error(); $this->db->rollback(); return -1; } - } - - $this->db->commit(); - return 1; - } - else - { - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - $this->error=$this->db->errno(); - $this->db->rollback(); - return -2; - } - else - { - $this->error=$this->db->error(); - $this->db->rollback(); - return -1; - } - } + } + } else return 0; } /** diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index ce4f498869c..ca1f1c77df4 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4161,7 +4161,7 @@ function getTaxesFromId($vatrate, $buyer=null, $seller=null, $firstparamisid=1) * @param Societe $buyer Company object * @param Societe $seller Company object * @param int $firstparamisid 1 if first param is id into table (use this if you can) - * @return array array(localtax_type1(1-6/0 if not found), rate localtax1, localtax_type1, rate localtax2, accountancycodecust, accountancycodesupp) + * @return array array(localtax_type1(1-6/0 if not found), rate localtax1, localtax_type2, rate localtax2, accountancycodecust, accountancycodesupp) * @see getTaxesFromId */ function getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0) diff --git a/htdocs/core/modules/supplier_payment/mod_supplier_payment_brodator.php b/htdocs/core/modules/supplier_payment/mod_supplier_payment_brodator.php index fb06c028aed..97c7b077b22 100644 --- a/htdocs/core/modules/supplier_payment/mod_supplier_payment_brodator.php +++ b/htdocs/core/modules/supplier_payment/mod_supplier_payment_brodator.php @@ -28,7 +28,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/modules/supplier_payment/modules_supplier /** * Class to manage customer payment numbering rules Ant */ -class mod_supplier_payment_brodator extends ModeleNumRefPayments +class mod_supplier_payment_brodator extends ModeleNumRefSupplierPayments { var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' var $error = ''; diff --git a/htdocs/core/modules/supplier_payment/mod_supplier_payment_bronan.php b/htdocs/core/modules/supplier_payment/mod_supplier_payment_bronan.php index e7146e2e1fd..c94ef4296c0 100644 --- a/htdocs/core/modules/supplier_payment/mod_supplier_payment_bronan.php +++ b/htdocs/core/modules/supplier_payment/mod_supplier_payment_bronan.php @@ -27,7 +27,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/modules/supplier_payment/modules_supplier /** * Class to manage customer payment numbering rules Cicada */ -class mod_supplier_payment_bronan extends ModeleNumRefPayments +class mod_supplier_payment_bronan extends ModeleNumRefSupplierPayments { var $version='dolibarr'; // 'development', 'experimental', 'dolibarr' var $prefix='SPAY'; diff --git a/htdocs/core/modules/supplier_payment/modules_supplier_payment.php b/htdocs/core/modules/supplier_payment/modules_supplier_payment.php index d8586777d30..56c5bd94ae0 100644 --- a/htdocs/core/modules/supplier_payment/modules_supplier_payment.php +++ b/htdocs/core/modules/supplier_payment/modules_supplier_payment.php @@ -48,11 +48,11 @@ abstract class ModelePDFSuppliersPayments extends CommonDocGenerator } /** - * \class ModeleNumRefPayments + * \class ModeleNumRefSupplierPayments * \brief Payment numbering references mother class */ -abstract class ModeleNumRefPayments +abstract class ModeleNumRefSupplierPayments { var $error=''; diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index e4e8fe8ea47..aec09b5ee23 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -479,6 +479,7 @@ if (empty($reshook)) } */ + // PREPARE SEND $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); @@ -1063,7 +1064,8 @@ if (empty($reshook)) $object_ligne = new ExpenseReportLine($db); - $vatrate = GETPOST('vatrate'); + $vatrate = GETPOST('vatrate','alpha'); // May be 8.5* (8.5NPROM) + $object_ligne->comments = GETPOST('comments'); $qty = GETPOST('qty','int'); if (empty($qty)) $qty=1; @@ -1125,13 +1127,34 @@ if (empty($reshook)) $object_ligne->fk_expensereport = $_POST['fk_expensereport']; $type = 0; // TODO What if service ? - $seller = ''; // seller is unknown - $tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller); + // We don't know seller and buyer for expense reports + $seller = $mysoc; + $buyer = new Societe($db); + + $localtaxes_type=getLocalTaxesFromRate($vatrate,0,$buyer,$seller); + + // Clean vat code + $vat_src_code=''; + + if (preg_match('/\((.*)\)/', $vatrate, $reg)) + { + $vat_src_code = $reg[1]; + $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. + } + $vatrate = preg_replace('/\*/','',$vatrate); + + $tmp = calcul_price_total($qty, $up, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller, $localtaxes_type); + + $object_ligne->vat_src_code = $vat_src_code; $object_ligne->vatrate = price2num($vatrate); $object_ligne->total_ttc = $tmp[2]; $object_ligne->total_ht = $tmp[0]; $object_ligne->total_tva = $tmp[1]; + $object_ligne->localtax1_tx = $localtaxes_type[1]; + $object_ligne->localtax2_tx = $localtaxes_type[3]; + $object_ligne->localtax1_type = $localtaxes_type[0]; + $object_ligne->localtax2_type = $localtaxes_type[2]; $result = $object_ligne->insert(); if ($result > 0) @@ -1862,7 +1885,8 @@ else { $objp = $db->fetch_object($resql); - print ''; + print ''; } print '"; + print ''; print ""; $totalpaid += $objp->amount; $i++; @@ -1900,21 +1925,21 @@ else if ($object->paid == 0) { - print ''; - print ''; + print ''; + print ''; $remaintopay = $object->total_ttc - $totalpaid; print ''; - print ''; + print ''; } - print "
'.$langs->trans("Type").''.$langs->trans("Amount").'
"; print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''.dol_print_date($db->jdate($objp->dp),'day')."
'.$langs->trans("None").'
".$langs->trans("AlreadyPaid")." :".price($totalpaye)."
".$langs->trans("AmountExpected")." :".price($object->amount)."
".$langs->trans("RemainderToPay")." :'.price($resteapayer)."
'; + print '
'; $paymentexpensereportstatic->id = $objp->rowid; $paymentexpensereportstatic->datepaye = $db->jdate($objp->dp); $paymentexpensereportstatic->ref = $objp->rowid; @@ -1893,6 +1917,7 @@ else print ''.price($objp->amount)."
'.$langs->trans("AlreadyPaid").':'.price($totalpaid).'
'.$langs->trans("AmountExpected").':'.price($object->total_ttc).'
'.$langs->trans("AlreadyPaid").':'.price($totalpaid).'
'.$langs->trans("AmountExpected").':'.price($object->total_ttc).'
'.$langs->trans("RemainderToPay").':'.price($remaintopay).'
'.price($remaintopay).'
"; $db->free($resql); } else { dol_print_error($db); } + print ""; print '
'; print '
'; @@ -2062,7 +2087,9 @@ else // VAT print ''; - print $form->load_tva('vatrate', (isset($_POST["vatrate"])?$_POST["vatrate"]:$objp->vatrate), $mysoc, ''); + $seller=$mysoc; + $buyer=new Societe($db); + print $form->load_tva('vatrate', (isset($_POST["vatrate"])?$_POST["vatrate"]:$objp->vatrate), $seller, $buyer, 0, 0, '', false, 1); print ''; // Unit price @@ -2148,7 +2175,7 @@ else print ''; $defaultvat=-1; if (! empty($conf->global->EXPENSEREPORT_NO_DEFAULT_VAT)) $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS = 'none'; - print $form->load_tva('vatrate', ($vatrate!=''?$vatrate:$defaultvat), $mysoc, '', 0, 0, '', false); + print $form->load_tva('vatrate', ($vatrate!=''?$vatrate:$defaultvat), $mysoc, '', 0, 0, '', false, 1); print ''; // Unit price diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index ffef31cad8b..00076a0e189 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -37,9 +37,9 @@ class ExpenseReport extends CommonObject var $picto = 'trip'; var $lignes=array(); - + public $date_debut; - + public $date_fin; var $fk_user_validator; @@ -65,7 +65,7 @@ class ExpenseReport extends CommonObject // Update var $date_modif; var $fk_user_modif; - + // Refus var $date_refuse; var $detail_refuse; @@ -128,17 +128,17 @@ class ExpenseReport extends CommonObject $now = dol_now(); $error = 0; - + // Check parameters - if (empty($this->date_debut) || empty($this->date_fin)) + if (empty($this->date_debut) || empty($this->date_fin)) { $this->error='ErrorFieldRequired'; return -1; } - + $fuserid = $this->fk_user_author; // Note fk_user_author is not the 'author' but the guy the expense report is for. if (empty($fuserid)) $fuserid = $user->id; - + $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; @@ -208,7 +208,7 @@ class ExpenseReport extends CommonObject $result=$this->update_price(); if ($result > 0) { - + if (!$notrigger) { // Call trigger @@ -262,19 +262,18 @@ class ExpenseReport extends CommonObject function createFromClone($fk_user_author) { global $user,$hookmanager; - + $error=0; - + if (empty($fk_user_author)) $fk_user_author = $user->id; - + $this->context['createfromclone'] = 'createfromclone'; - $this->db->begin(); - + // get extrafields so they will be clone //foreach($this->lines as $line) //$line->fetch_optionals($line->rowid); - + // Load source object $objFrom = clone $this; @@ -307,6 +306,7 @@ class ExpenseReport extends CommonObject // Call trigger $result=$this->call_trigger('EXPENSEREPORT_CLONE',$user); + if ($result < 0) $error++; // End call triggers } @@ -325,8 +325,8 @@ class ExpenseReport extends CommonObject return -1; } } - - + + /** * update * @@ -341,7 +341,7 @@ class ExpenseReport extends CommonObject $error = 0; $this->db->begin(); - + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; $sql.= " total_ht = ".$this->total_ht; $sql.= " , total_ttc = ".$this->total_ttc; @@ -455,7 +455,7 @@ class ExpenseReport extends CommonObject $this->fk_user_refuse = $obj->fk_user_refuse; $this->fk_user_cancel = $obj->fk_user_cancel; $this->fk_user_approve = $obj->fk_user_approve; - + $user_author = new User($this->db); if ($this->fk_user_author > 0) $user_author->fetch($this->fk_user_author); @@ -512,7 +512,7 @@ class ExpenseReport extends CommonObject { $error = 0; $this->db->begin(); - + $sql = "UPDATE ".MAIN_DB_PREFIX."expensereport"; $sql.= " SET fk_statut = 6, paid=1"; $sql.= " WHERE rowid = ".$id." AND fk_statut = 5"; @@ -533,7 +533,7 @@ class ExpenseReport extends CommonObject } // End call triggers } - + if (empty($error)) { $this->db->commit(); @@ -670,7 +670,7 @@ class ExpenseReport extends CommonObject $auser->fetch($obj->fk_user_approve); $this->user_approve = $auser; } - + } $this->db->free($resql); } @@ -704,8 +704,8 @@ class ExpenseReport extends CommonObject $this->date_fin = $now; $this->date_approve = $now; - $type_fees_id = 2; // TF_TRIP - + $type_fees_id = 2; // TF_TRIP + $this->status = 5; $this->fk_statut = 5; @@ -1078,14 +1078,14 @@ class ExpenseReport extends CommonObject { $now = dol_now(); $this->db->begin(); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= " SET ref = '".$this->db->escape($this->ref)."', fk_statut = 2, fk_user_valid = ".$fuser->id.", date_valid='".$this->db->idate($now)."'"; if ($update_number_int) { $sql.= ", ref_number_int = ".$ref_number_int; } $sql.= ' WHERE rowid = '.$this->id; - + $resql=$this->db->query($sql); if ($resql) { @@ -1099,7 +1099,7 @@ class ExpenseReport extends CommonObject } // End call triggers } - + if (empty($error)) { $this->db->commit(); @@ -1123,7 +1123,7 @@ class ExpenseReport extends CommonObject { dol_syslog(get_class($this)."::setValidate expensereport already with validated status", LOG_WARNING); } - + return 0; } @@ -1183,13 +1183,13 @@ class ExpenseReport extends CommonObject { $now=dol_now(); $error = 0; - + // date approval $this->date_approve = $this->db->idate($now); if ($this->fk_statut != 5) { $this->db->begin(); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= " SET ref = '".$this->db->escape($this->ref)."', fk_statut = 5, fk_user_approve = ".$fuser->id.","; $sql.= " date_approve='".$this->db->idate($this->date_approve)."'"; @@ -1206,7 +1206,7 @@ class ExpenseReport extends CommonObject } // End call triggers } - + if (empty($error)) { $this->db->commit(); @@ -1230,7 +1230,7 @@ class ExpenseReport extends CommonObject { dol_syslog(get_class($this)."::setApproved expensereport already with approve status", LOG_WARNING); } - + return 0; } @@ -1245,7 +1245,7 @@ class ExpenseReport extends CommonObject { $now = dol_now(); $error = 0; - + // date de refus if ($this->fk_statut != 99) { @@ -1261,7 +1261,7 @@ class ExpenseReport extends CommonObject $this->fk_user_refuse = $fuser->id; $this->detail_refuse = $details; $this->date_refuse = $now; - + if (!$notrigger) { // Call trigger @@ -1272,7 +1272,7 @@ class ExpenseReport extends CommonObject } // End call triggers } - + if (empty($error)) { $this->db->commit(); @@ -1308,11 +1308,11 @@ class ExpenseReport extends CommonObject function set_unpaid($fuser, $notrigger = 0) { $error = 0; - + if ($this->fk_c_deplacement_statuts != 5) { $this->db->begin(); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= " SET fk_statut = 5"; $sql.= ' WHERE rowid = '.$this->id; @@ -1331,7 +1331,7 @@ class ExpenseReport extends CommonObject } // End call triggers } - + if (empty($error)) { $this->db->commit(); @@ -1372,7 +1372,7 @@ class ExpenseReport extends CommonObject if ($this->fk_statut != 4) { $this->db->begin(); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= " SET fk_statut = 4, fk_user_cancel = ".$fuser->id; $sql.= ", date_cancel='".$this->db->idate($this->date_cancel)."'"; @@ -1393,7 +1393,7 @@ class ExpenseReport extends CommonObject } // End call triggers } - + if (empty($error)) { $this->db->commit(); @@ -1433,7 +1433,7 @@ class ExpenseReport extends CommonObject $sql = 'SELECT MAX(de.ref_number_int) as max'; $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' de'; - + $result = $this->db->query($sql); if($this->db->num_rows($result) > 0): @@ -1577,7 +1577,7 @@ class ExpenseReport extends CommonObject * @param int $rowid Line to edit * @param int $type_fees_id Type payment * @param int $projet_id Project id - * @param double $vatrate Vat rate + * @param double $vatrate Vat rate. Can be '8.5* (8.5NPROM...)' * @param string $comments Description * @param real $qty Qty * @param double $value_unit Value init @@ -1587,14 +1587,34 @@ class ExpenseReport extends CommonObject */ function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id) { - global $user; + global $user, $mysoc; if ($this->fk_statut==0 || $this->fk_statut==99) { $this->db->begin(); + $type = 0; // TODO What if type is service ? + + // We don't know seller and buyer for expense reports + $seller = $mysoc; + $buyer = new Societe($this->db); + + $localtaxes_type=getLocalTaxesFromRate($vatrate,0,$buyer,$seller); + + // Clean vat code + $vat_src_code=''; + + if (preg_match('/\((.*)\)/', $vatrate, $reg)) + { + $vat_src_code = $reg[1]; + $vatrate = preg_replace('/\s*\(.*\)/', '', $vatrate); // Remove code into vatrate. + } + $vatrate = preg_replace('/\*/','',$vatrate); + + $tmp = calcul_price_total($qty, $value_unit, 0, $vatrate, 0, 0, 0, 'TTC', 0, $type, $seller, $localtaxes_type); + // calcul de tous les totaux de la ligne - $total_ttc = price2num($qty*$value_unit, 'MT'); + //$total_ttc = price2num($qty*$value_unit, 'MT'); $tx_tva = $vatrate / 100; $tx_tva = $tx_tva + 1; @@ -1604,6 +1624,9 @@ class ExpenseReport extends CommonObject // fin calculs $ligne = new ExpenseReportLine($this->db); + + $ligne->rowid = $rowid; + $ligne->comments = $comments; $ligne->qty = $qty; $ligne->value_unit = $value_unit; @@ -1613,11 +1636,21 @@ class ExpenseReport extends CommonObject $ligne->fk_c_type_fees = $type_fees_id; $ligne->fk_projet = $projet_id; - $ligne->total_ht = $total_ht; - $ligne->total_tva = $total_tva; - $ligne->total_ttc = $total_ttc; - $ligne->vatrate = price2num($vatrate); - $ligne->rowid = $rowid; + //$ligne->total_ht = $total_ht; + //$ligne->total_tva = $total_tva; + //$ligne->total_ttc = $total_ttc; + //$ligne->vatrate = price2num($vatrate); + + $ligne->vat_src_code = $vat_src_code; + $ligne->vatrate = price2num($vatrate); + $ligne->total_ttc = $tmp[2]; + $ligne->total_ht = $tmp[0]; + $ligne->total_tva = $tmp[1]; + $ligne->localtax1_tx = $localtaxes_type[1]; + $ligne->localtax2_tx = $localtaxes_type[3]; + $ligne->localtax1_type = $localtaxes_type[0]; + $ligne->localtax2_type = $localtaxes_type[2]; + // Select des infos sur le type fees $sql = "SELECT c.code as code_type_fees, c.label as libelle_type_fees"; @@ -1758,7 +1791,7 @@ class ExpenseReport extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."usergroup_user as ugu, ".MAIN_DB_PREFIX."usergroup_rights as ur, ".MAIN_DB_PREFIX."rights_def as rd"; $sql.= " WHERE ugu.fk_usergroup = ur.fk_usergroup AND ur.fk_id = rd.id and rd.module = 'expensereport' AND rd.perms = 'approve'"; // Permission 'Approve'; //print $sql; - + dol_syslog(get_class($this)."::fetch_users_approver_expensereport sql=".$sql); $result = $this->db->query($sql); if($result) @@ -1895,7 +1928,7 @@ class ExpenseReport extends CommonObject $now=dol_now(); $userchildids = $user->getAllChildIds(1); - + $sql = "SELECT ex.rowid, ex.date_valid"; $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as ex"; if ($option == 'toapprove') $sql.= " WHERE ex.fk_statut = 2"; @@ -1927,7 +1960,7 @@ class ExpenseReport extends CommonObject while ($obj=$this->db->fetch_object($resql)) { $response->nbtodo++; - + if ($option == 'toapprove') { if ($this->db->jdate($obj->date_valid) < ($now - $conf->expensereport->approve->warning_delay)) { @@ -1951,7 +1984,7 @@ class ExpenseReport extends CommonObject return -1; } } - + /** * Return if an expense report is late or not * @@ -1961,11 +1994,11 @@ class ExpenseReport extends CommonObject public function hasDelay($option) { global $conf; - + //Only valid members if ($option == 'toapprove' && $this->status != 2) return false; if ($option == 'topay' && $this->status != 5) return false; - + $now = dol_now(); if ($option == 'toapprove') { @@ -1973,7 +2006,7 @@ class ExpenseReport extends CommonObject } else return ($this->datevalid?$this->datevalid:$this->date_valid) < ($now - $conf->expensereport->payment->warning_delay); - } + } } diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index d49d9df85d2..860783abaa1 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -896,7 +896,7 @@ if (empty($reshook)) } // Actions to build doc - $upload_dir = $conf->commande->dir_output; + $upload_dir = $conf->fournisseur->commande->dir_output; $permissioncreate = $user->rights->fournisseur->commande->creer; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index 531f42fd47f..e50c880c0ee 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -3,8 +3,8 @@ * Copyright (C) 2012-2016 Laurent Destailleur * Copyright (C) 2012-2016 Regis Houssin * Copyright (C) 2013 Juanjo Menent - * Copyright (C) 2014 Ferran Marcet * Copyright (C) 2017 Alexandre Spangaro + * Copyright (C) 2014-2017 Ferran Marcet * * 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 @@ -41,7 +41,6 @@ require_once DOL_DOCUMENT_ROOT.'/holiday/common.inc.php'; $myparam = GETPOST("myparam"); $action=GETPOST('action', 'alpha'); $id=GETPOST('id', 'int'); -$userid = GETPOST('userid')?GETPOST('userid'):$user->id; // Protection if external user if ($user->societe_id > 0) accessforbidden(); @@ -61,7 +60,8 @@ if ($action == 'create') $object = new Holiday($db); // If no right to create a request - if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all))) + $fuserid = GETPOST('fuserid'); + if (($fuserid == $user->id && empty($user->rights->holiday->write)) || ($fuserid != $user->id && empty($user->rights->holiday->write_all))) { $error++; setEventMessages($langs->trans('CantCreateCP'), null, 'errors'); @@ -86,7 +86,6 @@ if ($action == 'create') $valideur = GETPOST('valideur'); $description = trim(GETPOST('description')); - $userID = GETPOST('userID'); // If no type if ($type <= 0) @@ -722,7 +721,7 @@ llxHeader('', $langs->trans('CPTitreMenu')); if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create') { // Si l'utilisateur n'a pas le droit de faire une demande - if (($userid == $user->id && empty($user->rights->holiday->write)) || ($userid != $user->id && empty($user->rights->holiday->write_all))) + if (($fuserid == $user->id && empty($user->rights->holiday->write)) || ($fuserid != $user->id && empty($user->rights->holiday->write_all))) { $errors[]=$langs->trans('CantCreateCP'); } @@ -802,7 +801,6 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create // Formulaire de demande print ''."\n"; print ''."\n"; - print ''."\n"; dol_fiche_head(); @@ -833,10 +831,10 @@ if (empty($id) || $action == 'add' || $action == 'request' || $action == 'create print ''; if (empty($user->rights->holiday->write_all)) { - print $form->select_dolusers($userid, 'useridbis', 0, '', 1, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); - print ''; + print $form->select_dolusers($fuserid, 'useridbis', 0, '', 1, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); + print ''; } - else print $form->select_dolusers(GETPOST('userid')?GETPOST('userid'):$user->id,'userid',0,'',0); + else print $form->select_dolusers(GETPOST('fuserid')?GETPOST('fuserid'):$user->id,'fuserid',0,'',0); print ''; print ''; diff --git a/htdocs/holiday/list.php b/htdocs/holiday/list.php index c9147419650..ec881f04c57 100644 --- a/htdocs/holiday/list.php +++ b/htdocs/holiday/list.php @@ -70,7 +70,6 @@ $search_type = GETPOST('search_type','int'); // List of fields to search into when doing a "search in all" $fieldstosearchall = array( - 'cp.rowid'=>'Ref', 'cp.description'=>'Description', 'uu.lastname'=>'EmployeeLastname', 'uu.firstname'=>'EmployeeFirstname' @@ -124,7 +123,7 @@ $order = $db->order($sortfield,$sortorder).$db->plimit($limit + 1, $offset); // Ref if(!empty($search_ref)) { - $filter.= " AND cp.rowid LIKE '%".$db->escape($search_ref)."%'\n"; + $filter.= " AND cp.rowid = ".$db->escape($search_ref); } // Start date diff --git a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql index bfd9f1c3d53..65752a542ca 100755 --- a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql +++ b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql @@ -63,7 +63,7 @@ ALTER TABLE llx_bookmark ADD COLUMN entity integer DEFAULT 1 NOT NULL; ALTER TABLE llx_bookmark MODIFY COLUMN url varchar(255) NOT NULL; -ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN tms timestamp DEFAULT '2001-01-01 00:00:00'; +-- VMYSQL4.1 ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN tms timestamp DEFAULT '2001-01-01 00:00:00'; -- Clean corrupted values for tms -- VMYSQL4.1 SET sql_mode = 'ALLOW_INVALID_DATES'; @@ -74,7 +74,7 @@ ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN tms timestamp DEFAULT '2001-01- -- VMYSQL4.3 ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN date_fin DATETIME NULL DEFAULT NULL; -- VPGSQL8.2 ALTER TABLE llx_opensurvey_sondage ALTER COLUMN date_fin DROP NOT NULL; -ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN tms timestamp DEFAULT CURRENT_TIMESTAMP; +-- VMYSQL4.1 ALTER TABLE llx_opensurvey_sondage MODIFY COLUMN tms timestamp DEFAULT CURRENT_TIMESTAMP; ALTER TABLE llx_opensurvey_sondage ADD COLUMN entity integer DEFAULT 1 NOT NULL; @@ -204,9 +204,14 @@ CREATE TABLE llx_payment_salary ( fk_user_modif integer )ENGINE=innodb; + +DELETE FROM llx_product_batch where fk_product_stock NOT IN (SELECT rowid from llx_product_stock); + ALTER TABLE llx_product_batch ADD INDEX idx_fk_product_stock (fk_product_stock); ALTER TABLE llx_product_batch ADD CONSTRAINT fk_product_batch_fk_product_stock FOREIGN KEY (fk_product_stock) REFERENCES llx_product_stock (rowid); +DELETE FROM llx_expeditiondet_batch where fk_expeditiondet NOT IN (SELECT rowid from llx_expeditiondet); + ALTER TABLE llx_expeditiondet_batch ADD INDEX idx_fk_expeditiondet (fk_expeditiondet); ALTER TABLE llx_expeditiondet_batch ADD CONSTRAINT fk_expeditiondet_batch_fk_expeditiondet FOREIGN KEY (fk_expeditiondet) REFERENCES llx_expeditiondet(rowid); diff --git a/htdocs/product/stats/facture.php b/htdocs/product/stats/facture.php index aa3e10d82db..7117f0c03c0 100644 --- a/htdocs/product/stats/facture.php +++ b/htdocs/product/stats/facture.php @@ -145,7 +145,7 @@ if ($id > 0 || ! empty($ref)) elseif ($user->rights->facture->lire) { $sql = "SELECT DISTINCT s.nom as name, s.rowid as socid, s.code_client,"; - $sql.= " f.facnumber, f.datef, f.paye, f.fk_statut as statut, f.rowid as facid,"; + $sql.= " f.facnumber, f.datef, f.paye, f.type, f.fk_statut as statut, f.rowid as facid,"; $sql.= " d.rowid, d.total_ht as total_ht, d.qty"; // We must keep the d.rowid here to not loose record because of the distinct used to ignore duplicate line when link on societe_commerciaux is used if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user "; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; @@ -239,21 +239,22 @@ if ($id > 0 || ! empty($ref)) { $objp = $db->fetch_object($result); + $invoicestatic->id=$objp->facid; + $invoicestatic->ref=$objp->facnumber; + $societestatic->fetch($objp->socid); + $paiement = $invoicestatic->getSommePaiement(); print ''; print ''; - $invoicestatic->id=$objp->facid; - $invoicestatic->ref=$objp->facnumber; print $invoicestatic->getNomUrl(1); print "\n"; - $societestatic->fetch($objp->socid); print ''.$societestatic->getNomUrl(1).''; print "".$objp->code_client."\n"; print ''; print dol_print_date($db->jdate($objp->datef),'day').""; print ''.$objp->qty."\n"; print ''.price($objp->total_ht)."\n"; - print ''.$invoicestatic->LibStatut($objp->paye,$objp->statut,5).''; + print ''.$invoicestatic->LibStatut($objp->paye,$objp->statut,5,$paiement,$objp->type).''; print "\n"; $i++;