diff --git a/htdocs/admin/tools/listevents.php b/htdocs/admin/tools/listevents.php index f49886594a7..5b0991afdf6 100644 --- a/htdocs/admin/tools/listevents.php +++ b/htdocs/admin/tools/listevents.php @@ -69,13 +69,20 @@ $search_desc = GETPOST("search_desc", "alpha"); $search_ua = GETPOST("search_ua", "restricthtml"); $search_prefix_session = GETPOST("search_prefix_session", "restricthtml"); -if (GETPOST("date_startmonth") == '' || GETPOST("date_startmonth") > 0) { - $date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth"), GETPOST("date_startday"), GETPOST("date_startyear")); +$now = dol_now(); +$nowarray = dol_getdate($now); + +if (!GETPOSTISSET("date_startmonth")) { + $date_start = dol_get_first_day($nowarray['year'], $nowarray['mon'], 'tzuserrel'); +} else if (GETPOST("date_startmonth") > 0) { + $date_start = dol_mktime(0, 0, 0, GETPOST("date_startmonth", 'int'), GETPOST("date_startday", 'int'), GETPOST("date_startyear", 'int'), 'tzuserrel'); } else { $date_start = -1; } -if (GETPOST("date_endmonth") == '' || GETPOST("date_endmonth") > 0) { - $date_end = dol_mktime(23, 59, 59, GETPOST("date_endmonth"), GETPOST("date_endday"), GETPOST("date_endyear")); +if (!GETPOSTISSET("date_endmonth")) { + $date_end = dol_get_last_hour(dol_now('gmt'), 'tzuserrel'); +} elseif (GETPOST("date_endmonth") > 0) { + $date_end = dol_get_last_hour(dol_mktime(23, 59, 59, GETPOST("date_endmonth", 'int'), GETPOST("date_endday", 'int'), GETPOST("date_endyear", 'int'), 'tzuserrel'), 'tzuserrel'); } else { $date_end = -1; } @@ -85,8 +92,6 @@ if ($date_start > 0 && $date_end > 0 && $date_start > $date_end) { $date_end = $date_start + 86400; } -$now = dol_now(); -$nowarray = dol_getdate($now); if (empty($date_start)) { // We define date_start and date_end $date_start = dol_get_first_day($nowarray['year'], $nowarray['mon'], false); @@ -114,7 +119,6 @@ $arrayfields = array( ) ); - /* * Actions */ @@ -316,19 +320,22 @@ if ($result) { // Fields title search print ''; - print ''.$form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0).''; + print ''; + print $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzuserrel'); + print $form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0, 0, '', '', '', '', 1, '', '', 'tzuserrel'); + print ''; print ''; - print ''; + print ''; print ''; // IP print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; @@ -337,13 +344,13 @@ if ($result) { if (!empty($arrayfields['e.user_agent']['checked'])) { print ''; - print ''; + print ''; print ''; } if (!empty($arrayfields['e.prefix_session']['checked'])) { print ''; - print ''; + print ''; print ''; } @@ -376,7 +383,7 @@ if ($result) { print ''; // Date - print ''.dol_print_date($db->jdate($obj->dateevent), '%Y-%m-%d %H:%M:%S').''; + print ''.dol_print_date($db->jdate($obj->dateevent), '%Y-%m-%d %H:%M:%S', 'tzuserrel').''; // Code print ''.$obj->type.''; diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index bd427115a57..e0a9138244d 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -207,8 +207,8 @@ if (empty($reshook)) { $substitutionarray['__OTHER4__'] = $other4; $substitutionarray['__OTHER5__'] = $other5; $substitutionarray['__USER_SIGNATURE__'] = $signature; // Signature is empty when ran from command line or taken from user in parameter) - $substitutionarray['__CHECK_READ__'] = ''; - $substitutionarray['__UNSUBSCRIBE__'] = ''.$langs->trans("MailUnsubcribe").''; + $substitutionarray['__CHECK_READ__'] = ''; + $substitutionarray['__UNSUBSCRIBE__'] = ''.$langs->trans("MailUnsubcribe").''; $onlinepaymentenabled = 0; if (!empty($conf->paypal->enabled)) { diff --git a/htdocs/compta/bank/line.php b/htdocs/compta/bank/line.php index 7f113e120fc..419a0a41cdf 100644 --- a/htdocs/compta/bank/line.php +++ b/htdocs/compta/bank/line.php @@ -315,10 +315,11 @@ if ($result) { $i++; // Bank account - print ''.$langs->trans("Account").''; + print ''.$langs->trans("Account").''; print ''; if (!$objp->rappro && !$bankline->getVentilExportCompta()) { - $form->select_comptes($acct->id, 'accountid', 0, '', 0); + print img_picto('', 'bank_account', 'class="paddingright"'); + print $form->select_comptes($acct->id, 'accountid', 0, '', 0, '', 0, '', 1); } else { print $acct->getNomUrl(1, 'transactions', 'reflabel'); } @@ -566,7 +567,7 @@ if ($result) { // Bank line print ''.$form->editfieldkey('RubriquesTransactions', 'custcats', '', $object, 0).''; $cate_arbo = $form->select_all_categories(Categorie::TYPE_BANK_LINE, null, 'parent', null, null, 1); - print $form->multiselectarray('custcats', $cate_arbo, $arrayselected, null, null, null, null, "90%"); + print img_picto('', 'category', 'class="paddingright"').$form->multiselectarray('custcats', $cate_arbo, $arrayselected, null, null, null, null, "90%"); print ""; } diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index ad880470b50..1b9a579d1ab 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -335,14 +335,20 @@ class FactureRec extends CommonInvoice $facsrc->lines[$i]->special_code, $facsrc->lines[$i]->label, $facsrc->lines[$i]->fk_unit, - $facsrc->lines[$i]->multicurrency_subprice + $facsrc->lines[$i]->multicurrency_subprice, + 0, + 0, + null, + $facsrc->lines[$i]->pa_ht ); if ($result_insert < 0) { $error++; } else { $objectline = new FactureLigneRec($this->db); - if ($objectline->fetch($result_insert)) { + + $result2 = $objectline->fetch($result_insert); + if ($result2 > 0) { // Extrafields if (method_exists($facsrc->lines[$i], 'fetch_optionals')) { $facsrc->lines[$i]->fetch_optionals($facsrc->lines[$i]->id); @@ -353,6 +359,9 @@ class FactureRec extends CommonInvoice if ($result < 0) { $error++; } + } elseif ($result2 < 0) { + $this->errors[] = $objectline->error; + $error++; } } } @@ -403,6 +412,7 @@ class FactureRec extends CommonInvoice if ($error) { $this->db->rollback(); + return -3; } else { $this->db->commit(); return $this->id; @@ -494,14 +504,15 @@ class FactureRec extends CommonInvoice //$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON el.fk_target = f.rowid AND el.targettype = 'facture'"; $sql .= ' WHERE f.entity IN ('.getEntity('invoice').')'; if ($rowid) { - $sql .= ' AND f.rowid='.$rowid; + $sql .= ' AND f.rowid='.((int) $rowid); } elseif ($ref) { $sql .= " AND f.titre='".$this->db->escape($ref)."'"; + } else { + $sql .= ' AND f.rowid = 0'; } /* This field are not used for template invoice - if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'"; - if ($ref_int) $sql.= " AND f.ref_int='".$this->db->escape($ref_int)."'"; - */ + if ($ref_ext) $sql.= " AND f.ref_ext='".$this->db->escape($ref_ext)."'"; + */ $result = $this->db->query($sql); if ($result) { @@ -629,11 +640,11 @@ class FactureRec extends CommonInvoice $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.vat_src_code, l.tva_tx, '; $sql .= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise, l.remise_percent, l.subprice,'; - $sql .= ' l.info_bits, l.date_start_fill, l.date_end_fill, l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,'; + $sql .= ' l.info_bits, l.date_start_fill, l.date_end_fill, l.total_ht, l.total_tva, l.total_ttc, l.fk_product_fournisseur_price, l.buy_price_ht as pa_ht,'; //$sql.= ' l.situation_percent, l.fk_prev_id,'; //$sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise_percent, l.fk_remise_except, l.subprice,'; $sql .= ' l.rang, l.special_code,'; - //$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc, l.fk_code_ventilation, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,'; + //$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc, l.fk_code_ventilation, l.fk_product_fournisseur_price, l.buy_price_ht as pa_ht,'; $sql .= ' l.fk_unit, l.fk_contract_line,'; $sql .= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,'; $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc'; @@ -682,10 +693,16 @@ class FactureRec extends CommonInvoice $line->total_ht = $objp->total_ht; $line->total_tva = $objp->total_tva; $line->total_ttc = $objp->total_ttc; + //$line->code_ventilation = $objp->fk_code_ventilation; - $line->fk_fournprice = $objp->fk_fournprice; - $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht); - $line->pa_ht = $marginInfos[0]; + + $line->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price; + $line->fk_fournprice = $objp->fk_product_fournisseur_price; // For backward compatibility + + $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_product_fournisseur_price, $objp->pa_ht); + + $line->buyprice = $marginInfos[0]; + $line->pa_ht = $marginInfos[0]; // For backward compatibility $line->marge_tx = $marginInfos[1]; $line->marque_tx = $marginInfos[2]; $line->rang = $objp->rang; @@ -1962,6 +1979,10 @@ class FactureLigneRec extends CommonInvoiceLine $sql .= ' l.date_start_fill, l.date_end_fill, l.info_bits, l.total_ht, l.total_tva, l.total_ttc,'; $sql .= ' l.rang, l.special_code,'; $sql .= ' l.fk_unit, l.fk_contract_line,'; + $sql .= ' l.import_key, l.fk_multicurrency,'; + $sql .= ' l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,'; + $sql .= ' l.buy_price_ht, l.fk_product_fournisseur_price,'; + $sql .= ' l.fk_user_author, l.fk_user_modif,'; $sql .= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc'; $sql .= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l'; $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; @@ -2008,7 +2029,17 @@ class FactureLigneRec extends CommonInvoiceLine $this->special_code = $objp->special_code; $this->fk_unit = $objp->fk_unit; $this->fk_contract_line = $objp->fk_contract_line; - + $this->import_key = $objp->import_key; + $this->fk_multicurrency = $objp->fk_multicurrency; + $this->multicurrency_code = $objp->multicurrency_code; + $this->multicurrency_subprice = $objp->multicurrency_subprice; + $this->multicurrency_total_ht = $objp->multicurrency_total_ht; + $this->multicurrency_total_tva = $objp->multicurrency_total_tva; + $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc; + $this->buy_price_ht = $objp->buy_price_ht; + $this->fk_product_fournisseur_price = $objp->fk_product_fournisseur_price; + $this->fk_user_author = $objp->fk_user_author; + $this->fk_user_modif = $objp->fk_user_modif; $this->db->free($result); return 1; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index bd14a778f78..a78fc550150 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -917,8 +917,9 @@ class Facture extends CommonInvoice $localtax1_tx = $_facrec->lines[$i]->localtax1_tx; $localtax2_tx = $_facrec->lines[$i]->localtax2_tx; - $fk_product_fournisseur_price = empty($_facrec->lines[$i]->fk_product_fournisseur_price) ?null:$_facrec->lines[$i]->fk_product_fournisseur_price; + $fk_product_fournisseur_price = empty($_facrec->lines[$i]->fk_product_fournisseur_price) ? null : $_facrec->lines[$i]->fk_product_fournisseur_price; $buyprice = empty($_facrec->lines[$i]->buyprice) ? 0 : $_facrec->lines[$i]->buyprice; + // If buyprice not defined from template invoice, we try to guess the best value if (!$buyprice && $_facrec->lines[$i]->fk_product > 0) { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; diff --git a/htdocs/compta/paiement/cheque/card.php b/htdocs/compta/paiement/cheque/card.php index e941f532efa..847dae1bc29 100644 --- a/htdocs/compta/paiement/cheque/card.php +++ b/htdocs/compta/paiement/cheque/card.php @@ -364,8 +364,9 @@ if ($action == 'new') { print ''; print '
'; - $sql = "SELECT ba.rowid as bid, b.datec as datec, b.dateo as date, b.rowid as transactionid, "; - $sql .= " b.amount, ba.label, b.emetteur, b.num_chq, b.banque,"; + $sql = "SELECT ba.rowid as bid, ba.label,"; + $sql .= " b.rowid as transactionid, b.label as transactionlabel, b.datec as datec, b.dateo as date, "; + $sql .= " b.amount, b.emetteur, b.num_chq, b.banque,"; $sql .= " p.rowid as paymentid, p.ref as paymentref"; $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid"; @@ -393,6 +394,8 @@ if ($action == 'new') { $lines[$obj->bid][$i]["numero"] = $obj->num_chq; $lines[$obj->bid][$i]["banque"] = $obj->banque; $lines[$obj->bid][$i]["id"] = $obj->transactionid; + $lines[$obj->bid][$i]["ref"] = $obj->transactionid; + $lines[$obj->bid][$i]["label"] = $obj->transactionlabel; $lines[$obj->bid][$i]["paymentid"] = $obj->paymentid; $lines[$obj->bid][$i]["paymentref"] = $obj->paymentref; $i++; @@ -473,8 +476,9 @@ if ($action == 'new') { print ''; // Link to bank transaction print ''; - $accountlinestatic->rowid = $value["id"]; - if ($accountlinestatic->rowid) { + $accountlinestatic->id = $value["id"]; + $accountlinestatic->ref = $value["ref"]; + if ($accountlinestatic->id > 0) { print $accountlinestatic->getNomUrl(1); } else { print ' '; @@ -594,7 +598,7 @@ if ($action == 'new') { // List of bank checks - $sql = "SELECT b.rowid, b.amount, b.num_chq, b.emetteur,"; + $sql = "SELECT b.rowid, b.rowid as ref, b.label, b.amount, b.num_chq, b.emetteur,"; $sql .= " b.dateo as date, b.datec as datec, b.banque,"; $sql .= " p.rowid as pid, p.ref as pref, ba.rowid as bid, p.statut"; $sql .= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; @@ -648,8 +652,9 @@ if ($action == 'new') { print ''; // Link to bank transaction print ''; - $accountlinestatic->rowid = $objp->rowid; - if ($accountlinestatic->rowid) { + $accountlinestatic->id = $objp->rowid; + $accountlinestatic->ref = $objp->ref; + if ($accountlinestatic->id > 0) { print $accountlinestatic->getNomUrl(1); } else { print ' '; diff --git a/htdocs/core/actions_addupdatedelete.inc.php b/htdocs/core/actions_addupdatedelete.inc.php index d7dcbf699c8..f871ed73de8 100644 --- a/htdocs/core/actions_addupdatedelete.inc.php +++ b/htdocs/core/actions_addupdatedelete.inc.php @@ -74,9 +74,9 @@ if ($action == 'add' && !empty($permissiontoadd)) { if (in_array($object->fields[$key]['type'], array('text', 'html'))) { $value = GETPOST($key, 'restricthtml'); } elseif ($object->fields[$key]['type'] == 'date') { - $value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); + $value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); // for date without hour, we use gmt } elseif ($object->fields[$key]['type'] == 'datetime') { - $value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); + $value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), GETPOST($key.'sec', 'int'), GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'), 'tzuserrel'); } elseif ($object->fields[$key]['type'] == 'duration') { $value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int'); } elseif (preg_match('/^(integer|price|real|double)/', $object->fields[$key]['type'])) { @@ -174,9 +174,9 @@ if ($action == 'update' && !empty($permissiontoadd)) { $value = GETPOST($key, 'restricthtml'); } } elseif ($object->fields[$key]['type'] == 'date') { - $value = dol_mktime(12, 0, 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); + $value = dol_mktime(12, 0, 0, GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int')); // for date without hour, we use gmt } elseif ($object->fields[$key]['type'] == 'datetime') { - $value = dol_mktime(GETPOST($key.'hour'), GETPOST($key.'min'), 0, GETPOST($key.'month'), GETPOST($key.'day'), GETPOST($key.'year')); + $value = dol_mktime(GETPOST($key.'hour', 'int'), GETPOST($key.'min', 'int'), GETPOST($key.'sec', 'int'), GETPOST($key.'month', 'int'), GETPOST($key.'day', 'int'), GETPOST($key.'year', 'int'), 'tzuserrel'); } elseif ($object->fields[$key]['type'] == 'duration') { if (GETPOST($key.'hour', 'int') != '' || GETPOST($key.'min', 'int') != '') { $value = 60 * 60 * GETPOST($key.'hour', 'int') + 60 * GETPOST($key.'min', 'int'); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1bbf7450a98..f4bad5e5167 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -6455,11 +6455,10 @@ abstract class CommonObject } } - if (in_array($type, array('date', 'datetime'))) { + if (in_array($type, array('date'))) { $tmp = explode(',', $size); $newsize = $tmp[0]; - - $showtime = in_array($type, array('datetime')) ? 1 : 0; + $showtime = 0; // Do not show current date when field not required (see selectDate() method) if (!$required && $value == '') { @@ -6468,6 +6467,16 @@ abstract class CommonObject // TODO Must also support $moreparam $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); + } elseif (in_array($type, array('datetime'))) { + $tmp = explode(',', $size); + $newsize = $tmp[0]; + $showtime = 1; + + // Do not show current date when field not required (see selectDate() method) + if (!$required && $value == '') $value = '-1'; + + // TODO Must also support $moreparam + $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1, '', '', '', 1, '', '', 'tzuserrel'); } elseif (in_array($type, array('duration'))) { $out = $form->select_duration($keyprefix.$key.$keysuffix, $value, 0, 'text', 0, 1); } elseif (in_array($type, array('int', 'integer'))) { @@ -7025,13 +7034,13 @@ abstract class CommonObject $value = $this->getLibStatut(3); } elseif ($type == 'date') { if (!empty($value)) { - $value = dol_print_date($value, 'day'); + $value = dol_print_date($value, 'day'); // We suppose dates without time are always gmt (storage of course + output) } else { $value = ''; } } elseif ($type == 'datetime' || $type == 'timestamp') { if (!empty($value)) { - $value = dol_print_date($value, 'dayhour'); + $value = dol_print_date($value, 'dayhour', 'tzuserrel'); } else { $value = ''; } @@ -7410,12 +7419,21 @@ abstract class CommonObject } // Convert date into timestamp format (value in memory must be a timestamp) - if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date', 'datetime'))) { + if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('date'))) { $datenotinstring = $this->array_options['options_'.$key]; if (!is_numeric($this->array_options['options_'.$key])) { // For backward compatibility $datenotinstring = $this->db->jdate($datenotinstring); } - $value = (GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) ? dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min", 'int', 3), 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year", 'int', 3)) : $datenotinstring; + $value = (GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) ? dol_mktime(12, 0, 0, GETPOST($keyprefix.'options_'.$key.$keysuffix."month", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year", 'int', 3)) : $datenotinstring; + } + if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('datetime'))) + { + $datenotinstring = $this->array_options['options_'.$key]; + if (!is_numeric($this->array_options['options_'.$key])) // For backward compatibility + { + $datenotinstring = $this->db->jdate($datenotinstring); + } + $value = (GETPOSTISSET($keyprefix.'options_'.$key.$keysuffix)) ? dol_mktime(GETPOST($keyprefix.'options_'.$key.$keysuffix."hour", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."min", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."sec", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."month", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."day", 'int', 3), GETPOST($keyprefix.'options_'.$key.$keysuffix."year", 'int', 3), 'tzuserrel') : $datenotinstring; } // Convert float submited string into real php numeric (value in memory must be a php numeric) if (in_array($extrafields->attributes[$this->table_element]['type'][$key], array('price', 'double'))) { @@ -8174,12 +8192,14 @@ abstract class CommonObject */ public function setVarsFromFetchObj(&$obj) { + global $db; + foreach ($this->fields as $field => $info) { if ($this->isDate($info)) { - if (empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') { - $this->{$field} = 0; + if (is_null($obj->{$field}) || $obj->{$field} === '' || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') { + $this->{$field} = ''; } else { - $this->{$field} = strtotime($obj->{$field}); + $this->{$field} = $db->jdate($obj->{$field}); } } elseif ($this->isArray($info)) { if (!empty($obj->{$field})) { diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 5a5b06054ff..53ad2c5b649 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1062,11 +1062,10 @@ class ExtraFields } } - if (in_array($type, array('date', 'datetime'))) { + if (in_array($type, array('date'))) { $tmp = explode(',', $size); $newsize = $tmp[0]; - - $showtime = in_array($type, array('datetime')) ? 1 : 0; + $showtime = 0; // Do not show current date when field not required (see selectDate() method) if (!$required && $value == '') { @@ -1079,16 +1078,41 @@ class ExtraFields 'start' => isset($value['start']) ? $value['start'] : '', 'end' => isset($value['end']) ? $value['end'] : '' ); - $out = '
' - . $form->selectDate($prefill['start'], $keyprefix.$key.$keysuffix.'_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")) - . '
' - . $form->selectDate($prefill['end'], $keyprefix.$key.$keysuffix.'_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")) - . '
'; + $out = '
'; + $out .= $form->selectDate($prefill['start'], $keyprefix.$key.$keysuffix.'_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From")); + $out .= '
'; + $out .= $form->selectDate($prefill['end'], $keyprefix.$key.$keysuffix.'_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to")); + $out .= '
'; } else { // TODO Must also support $moreparam $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1); } - } elseif (in_array($type, array('int', 'integer'))) { + } elseif (in_array($type, array('datetime'))) { + $tmp = explode(',', $size); + $newsize = $tmp[0]; + $showtime = 1; + + // Do not show current date when field not required (see selectDate() method) + if (!$required && $value == '') { + $value = '-1'; + } + + if ($mode == 1) { + // search filter on a date extrafield shows two inputs to select a date range + $prefill = array( + 'start' => isset($value['start']) ? $value['start'] : '', + 'end' => isset($value['end']) ? $value['end'] : '' + ); + $out = '
'; + $out .= $form->selectDate($prefill['start'], $keyprefix.$key.$keysuffix.'_start', 1, 1, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("From"), 'tzuserrel'); + $out .= '
'; + $out .= $form->selectDate($prefill['end'], $keyprefix.$key.$keysuffix.'_end', 1, 1, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"), 'tzuserrel'); + $out .= '
'; + } else { + // TODO Must also support $moreparam + $out = $form->selectDate($value, $keyprefix.$key.$keysuffix, $showtime, $showtime, $required, '', 1, (($keyprefix != 'search_' && $keyprefix != 'search_options_') ? 1 : 0), 0, 1, '', '', '', 1, '', '', 'tzuserrel'); + } + } elseif (in_array($type, array('int', 'integer'))) { $tmp = explode(',', $size); $newsize = $tmp[0]; $out = ''; @@ -1611,10 +1635,10 @@ class ExtraFields $showsize = 0; if ($type == 'date') { $showsize = 10; - $value = dol_print_date($value, 'day'); + $value = dol_print_date($value, 'day'); // For date without hour, date is always GMT for storage and output } elseif ($type == 'datetime') { $showsize = 19; - $value = dol_print_date($value, 'dayhour'); + $value = dol_print_date($value, 'dayhour', 'tzuserrel'); } elseif ($type == 'int') { $showsize = 10; } elseif ($type == 'double') { @@ -2064,12 +2088,10 @@ class ExtraFields if (in_array($key_type, array('date'))) { // Clean parameters - // TODO GMT date in memory must be GMT so we should add gm=true in parameters - $value_key = dol_mktime(0, 0, 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); + $value_key = dol_mktime(12, 0, 0, GETPOST("options_".$key."month", 'int'), GETPOST("options_".$key."day", 'int'), GETPOST("options_".$key."year", 'int')); } elseif (in_array($key_type, array('datetime'))) { // Clean parameters - // TODO GMT date in memory must be GMT so we should add gm=true in parameters - $value_key = dol_mktime($_POST["options_".$key."hour"], $_POST["options_".$key."min"], 0, $_POST["options_".$key."month"], $_POST["options_".$key."day"], $_POST["options_".$key."year"]); + $value_key = dol_mktime(GETPOST("options_".$key."hour", 'int'), GETPOST("options_".$key."min", 'int'), GETPOST("options_".$key."sec", 'int'), GETPOST("options_".$key."month", 'int'), GETPOST("options_".$key."day", 'int'), GETPOST("options_".$key."year", 'int'), 'tzuserrel'); } elseif (in_array($key_type, array('checkbox', 'chkbxlst'))) { $value_arr = GETPOST("options_".$key, 'array'); // check if an array if (!empty($value_arr)) { @@ -2134,32 +2156,33 @@ class ExtraFields $key_type = $this->attributes[$extrafieldsobjectkey]['type'][$key]; } - if (in_array($key_type, array('date', 'datetime'))) { + if (in_array($key_type, array('date'))) { $dateparamname_start = $keysuffix . 'options_' . $key . $keyprefix . '_start'; $dateparamname_end = $keysuffix . 'options_' . $key . $keyprefix . '_end'; if (GETPOSTISSET($dateparamname_start . 'year') && GETPOSTISSET($dateparamname_end . 'year')) { // values provided as a date pair (start date + end date), each date being broken down as year, month, day, etc. $value_key = array( - 'start' => dol_mktime( - 0, - 0, - 0, - GETPOST($dateparamname_start . 'month', 'int'), - GETPOST($dateparamname_start . 'day', 'int'), - GETPOST($dateparamname_start . 'year', 'int') - ), - 'end' => dol_mktime( - 23, - 59, - 59, - GETPOST($dateparamname_end . 'month', 'int'), - GETPOST($dateparamname_end . 'day', 'int'), - GETPOST($dateparamname_end . 'year', 'int') - ) + 'start' => dol_mktime(0, 0, 0, GETPOST($dateparamname_start . 'month', 'int'), GETPOST($dateparamname_start . 'day', 'int'), GETPOST($dateparamname_start . 'year', 'int')), + 'end' => dol_mktime(23, 59, 59, GETPOST($dateparamname_end . 'month', 'int'), GETPOST($dateparamname_end . 'day', 'int'), GETPOST($dateparamname_end . 'year', 'int')) ); } elseif (GETPOSTISSET($keysuffix."options_".$key.$keyprefix."year")) { // Clean parameters - $value_key = dol_mktime(GETPOST($keysuffix."options_".$key.$keyprefix."hour", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."min", 'int'), 0, GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int')); + $value_key = dol_mktime(12, 0, 0, GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int')); + } else { + continue; // Value was not provided, we should not set it. + } + } elseif (in_array($key_type, array('datetime'))) { + $dateparamname_start = $keysuffix . 'options_' . $key . $keyprefix . '_start'; + $dateparamname_end = $keysuffix . 'options_' . $key . $keyprefix . '_end'; + if (GETPOSTISSET($dateparamname_start . 'year') && GETPOSTISSET($dateparamname_end . 'year')) { + // values provided as a date pair (start date + end date), each date being broken down as year, month, day, etc. + $value_key = array( + 'start' => dol_mktime(GETPOST($dateparamname_start . 'hour', 'int'), GETPOST($dateparamname_start . 'min', 'int'), GETPOST($dateparamname_start . 'sec', 'int'), GETPOST($dateparamname_start . 'month', 'int'), GETPOST($dateparamname_start . 'day', 'int'), GETPOST($dateparamname_start . 'year', 'int'), 'tzuserrel'), + 'end' => dol_mktime(GETPOST($dateparamname_end . 'hour', 'int'), GETPOST($dateparamname_start . 'min', 'int'), GETPOST($dateparamname_start . 'sec', 'int'), GETPOST($dateparamname_end . 'month', 'int'), GETPOST($dateparamname_end . 'day', 'int'), GETPOST($dateparamname_end . 'year', 'int'), 'tzuserrel') + ); + } elseif (GETPOSTISSET($keysuffix."options_".$key.$keyprefix."year")) { + // Clean parameters + $value_key = dol_mktime(GETPOST($keysuffix."options_".$key.$keyprefix."hour", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."min", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."sec", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."month", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."day", 'int'), GETPOST($keysuffix."options_".$key.$keyprefix."year", 'int'), 'tzuserrel'); } else { continue; // Value was not provided, we should not set it. } diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index c220e890a2d..7edaada2f1c 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -2,6 +2,7 @@ /* Copyright (C) 2013-2015 Jean-François FERRY * Copyright (C) 2016 Christophe Battarel * Copyright (C) 2019 Frédéric France + * Copyright (C) 2021 Juanjo Menent * * 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 @@ -517,7 +518,7 @@ class FormTicket print ' selected="selected"'; } elseif ($selected == $id) { print ' selected="selected"'; - } elseif ($arraytypes['use_default'] == "1" && !$empty) { + } elseif ($arraytypes['use_default'] == "1" && !$selected && !$empty) { print ' selected="selected"'; } @@ -612,7 +613,7 @@ class FormTicket print ' selected="selected"'; } elseif ($selected == $id) { print ' selected="selected"'; - } elseif ($arraycategories['use_default'] == "1" && !$empty) { + } elseif ($arraycategories['use_default'] == "1" && !$selected && !$empty) { print ' selected="selected"'; } @@ -713,7 +714,7 @@ class FormTicket print ' selected="selected"'; } elseif ($selected == $id) { print ' selected="selected"'; - } elseif ($arrayseverities['use_default'] == "1" && !$empty) { + } elseif ($arrayseverities['use_default'] == "1" && !$selected && !$empty) { print ' selected="selected"'; } diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index 426b486a8cf..ecf1cf999de 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -546,24 +546,28 @@ function dol_get_last_day($year, $month = 12, $gm = false) * Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59) * * @param int $date Date GMT + * @param mixed $gm False or 0 or 'tzserver' = Return date to compare with server TZ, + * True or 1 or 'gmt' to compare with GMT date. * @return int Date for last hour of a given date */ -function dol_get_last_hour($date) +function dol_get_last_hour($date, $gm = 'tzserver') { $tmparray = dol_getdate($date); - return dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year'], false); + return dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year'], $gm); } /** * Return GMT time for first hour of a given GMT date (it removes hours, min and second part) * - * @param int $date Date + * @param int $date Date GMT + * @param mixed $gm False or 0 or 'tzserver' = Return date to compare with server TZ, + * True or 1 or 'gmt' to compare with GMT date. * @return int Date for last hour of a given date */ -function dol_get_first_hour($date) +function dol_get_first_hour($date, $gm = 'tzserver') { $tmparray = dol_getdate($date); - return dol_mktime(0, 0, 0, $tmparray['mon'], $tmparray['mday'], $tmparray['year'], false); + return dol_mktime(0, 0, 0, $tmparray['mon'], $tmparray['mday'], $tmparray['year'], $gm); } /** Return first day of week for a date. First day of week may be monday if option MAIN_START_WEEK is 1. diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 626baa48c40..f48d30d07c2 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4277,7 +4277,7 @@ function img_searchclear($titlealt = 'default', $other = '') * @param string $text Text info * @param integer $infoonimgalt Info is shown only on alt of star picto, otherwise it is show on output after the star picto * @param int $nodiv No div - * @param string $admin '1'=Info for admin users. '0'=Info for standard users (change only the look), 'error','xxx'=Other + * @param string $admin '1'=Info for admin users. '0'=Info for standard users (change only the look), 'error', 'warning', 'xxx'=Other * @param string $morecss More CSS ('', 'warning', 'error') * @param string $textfordropdown Show a text to click to dropdown the info box. * @return string String with info text diff --git a/htdocs/core/lib/ticket.lib.php b/htdocs/core/lib/ticket.lib.php index c7f3e0612ce..472cf19e45d 100644 --- a/htdocs/core/lib/ticket.lib.php +++ b/htdocs/core/lib/ticket.lib.php @@ -282,12 +282,10 @@ function show_ticket_messaging($conf, $langs, $db, $filterobj, $objcon = '', $no dol_print_error('', 'BadParameter'); } - $out = ''; $histo = array(); $numaction = 0; $now = dol_now(); - // Open DSI -- Fix order by -- Begin $sortfield_list = explode(',', $sortfield); $sortfield_label_list = array('a.id' => 'id', 'a.datep' => 'dp', 'a.percent' => 'percent'); $sortfield_new_list = array(); @@ -297,7 +295,7 @@ function show_ticket_messaging($conf, $langs, $db, $filterobj, $objcon = '', $no $sortfield_new = implode(',', $sortfield_new_list); if (!empty($conf->agenda->enabled)) { - // Recherche histo sur actioncomm + // Search histo on actioncomm if (is_object($objcon) && $objcon->id > 0) { $sql = "SELECT DISTINCT a.id, a.label as label,"; } else { @@ -464,87 +462,97 @@ function show_ticket_messaging($conf, $langs, $db, $filterobj, $objcon = '', $no $sql = $sql2; } - //TODO Add limit in nb of results - $sql .= $db->order($sortfield_new, $sortorder); + // TODO Add limit in nb of results + if ($sql) { // May not be defined if module Agenda is not enabled and mailing module disabled too + $sql .= $db->order($sortfield_new, $sortorder); - dol_syslog("company.lib::show_actions_done", LOG_DEBUG); - $resql = $db->query($sql); - if ($resql) { - $i = 0; - $num = $db->num_rows($resql); + dol_syslog("company.lib::show_actions_done", LOG_DEBUG); + $resql = $db->query($sql); + if ($resql) { + $i = 0; + $num = $db->num_rows($resql); - while ($i < $num) { - $obj = $db->fetch_object($resql); + while ($i < $num) { + $obj = $db->fetch_object($resql); - if ($obj->type == 'action') { - $contactaction = new ActionComm($db); - $contactaction->id = $obj->id; - $result = $contactaction->fetchResources(); - if ($result < 0) { - dol_print_error($db); - setEventMessage("company.lib::show_actions_done Error fetch ressource", 'errors'); + if ($obj->type == 'action') { + $contactaction = new ActionComm($db); + $contactaction->id = $obj->id; + $result = $contactaction->fetchResources(); + if ($result < 0) { + dol_print_error($db); + setEventMessage("company.lib::show_actions_done Error fetch ressource", 'errors'); + } + + //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))"; + //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))"; + $tododone = ''; + if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->datep > $now)) { + $tododone = 'todo'; + } + + $histo[$numaction] = array( + 'type'=>$obj->type, + 'tododone'=>$tododone, + 'id'=>$obj->id, + 'datestart'=>$db->jdate($obj->dp), + 'dateend'=>$db->jdate($obj->dp2), + 'note'=>$obj->label, + 'message'=>$obj->message, + 'percent'=>$obj->percent, + + 'userid'=>$obj->user_id, + 'login'=>$obj->user_login, + 'userfirstname'=>$obj->user_firstname, + 'userlastname'=>$obj->user_lastname, + 'userphoto'=>$obj->user_photo, + + 'contact_id'=>$obj->fk_contact, + 'socpeopleassigned' => $contactaction->socpeopleassigned, + 'lastname'=>$obj->lastname, + 'firstname'=>$obj->firstname, + 'fk_element'=>$obj->fk_element, + 'elementtype'=>$obj->elementtype, + // Type of event + 'acode'=>$obj->acode, + 'alabel'=>$obj->alabel, + 'libelle'=>$obj->alabel, // deprecated + 'apicto'=>$obj->apicto + ); + } else { + $histo[$numaction] = array( + 'type'=>$obj->type, + 'tododone'=>'done', + 'id'=>$obj->id, + 'datestart'=>$db->jdate($obj->dp), + 'dateend'=>$db->jdate($obj->dp2), + 'note'=>$obj->label, + 'message'=>$obj->message, + 'percent'=>$obj->percent, + 'acode'=>$obj->acode, + + 'userid'=>$obj->user_id, + 'login'=>$obj->user_login, + 'userfirstname'=>$obj->user_firstname, + 'userlastname'=>$obj->user_lastname, + 'userphoto'=>$obj->user_photo + ); } - //if ($donetodo == 'todo') $sql.= " AND ((a.percent >= 0 AND a.percent < 100) OR (a.percent = -1 AND a.datep > '".$db->idate($now)."'))"; - //elseif ($donetodo == 'done') $sql.= " AND (a.percent = 100 OR (a.percent = -1 AND a.datep <= '".$db->idate($now)."'))"; - $tododone = ''; - if (($obj->percent >= 0 and $obj->percent < 100) || ($obj->percent == -1 && $obj->datep > $now)) { - $tododone = 'todo'; - } - - $histo[$numaction] = array( - 'type'=>$obj->type, - 'tododone'=>$tododone, - 'id'=>$obj->id, - 'datestart'=>$db->jdate($obj->dp), - 'dateend'=>$db->jdate($obj->dp2), - 'note'=>$obj->label, - 'message'=>$obj->message, - 'percent'=>$obj->percent, - - 'userid'=>$obj->user_id, - 'login'=>$obj->user_login, - 'userfirstname'=>$obj->user_firstname, - 'userlastname'=>$obj->user_lastname, - 'userphoto'=>$obj->user_photo, - - 'contact_id'=>$obj->fk_contact, - 'socpeopleassigned' => $contactaction->socpeopleassigned, - 'lastname'=>$obj->lastname, - 'firstname'=>$obj->firstname, - 'fk_element'=>$obj->fk_element, - 'elementtype'=>$obj->elementtype, - // Type of event - 'acode'=>$obj->acode, - 'alabel'=>$obj->alabel, - 'libelle'=>$obj->alabel, // deprecated - 'apicto'=>$obj->apicto - ); - } else { - $histo[$numaction] = array( - 'type'=>$obj->type, - 'tododone'=>'done', - 'id'=>$obj->id, - 'datestart'=>$db->jdate($obj->dp), - 'dateend'=>$db->jdate($obj->dp2), - 'note'=>$obj->label, - 'message'=>$obj->message, - 'percent'=>$obj->percent, - 'acode'=>$obj->acode, - - 'userid'=>$obj->user_id, - 'login'=>$obj->user_login, - 'userfirstname'=>$obj->user_firstname, - 'userlastname'=>$obj->user_lastname, - 'userphoto'=>$obj->user_photo - ); + $numaction++; + $i++; } - - $numaction++; - $i++; + } else { + dol_print_error($db); } - } else { - dol_print_error($db); + } + + // Set $out to sow events + $out = ''; + + if (empty($conf->agenda->enabled)) { + $langs->loadLangs(array("admin", "errors")); + $out = info_admin($langs->trans("WarningModuleXDisabledSoYouMayMissEventHere", $langs->transnoentitiesnoconv("Module2400Name")), 0, 0, 'warning'); } if (!empty($conf->agenda->enabled) || (!empty($conf->mailing->enabled) && !empty($objcon->email))) { diff --git a/htdocs/core/modules/mailings/modules_mailings.php b/htdocs/core/modules/mailings/modules_mailings.php index 728437560bb..d875c3695a3 100644 --- a/htdocs/core/modules/mailings/modules_mailings.php +++ b/htdocs/core/modules/mailings/modules_mailings.php @@ -161,6 +161,7 @@ class MailingTargets // This can't be abstract as it is used for some method public function addTargetsToDatabase($mailing_id, $cibles) { global $conf; + global $dolibarr_main_instance_unique_id; $this->db->begin(); @@ -183,7 +184,7 @@ class MailingTargets // This can't be abstract as it is used for some method $sql .= "'".$this->db->escape($targetarray['other'])."',"; $sql .= "'".$this->db->escape($targetarray['source_url'])."',"; $sql .= (empty($targetarray['source_id']) ? 'null' : "'".$this->db->escape($targetarray['source_id'])."'").","; - $sql .= "'".$this->db->escape(dol_hash($targetarray['email'].';'.$targetarray['lastname'].';'.$mailing_id.';'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY))."',"; + $sql .= "'".$this->db->escape(dol_hash($dolibarr_main_instance_unique_id.';'.$targetarray['email'].';'.$targetarray['lastname'].';'.$mailing_id.';'.$conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY), 'md5')."',"; $sql .= "'".$this->db->escape($targetarray['source_type'])."')"; dol_syslog(__METHOD__, LOG_DEBUG); $result = $this->db->query($sql); diff --git a/htdocs/core/tpl/extrafields_view.tpl.php b/htdocs/core/tpl/extrafields_view.tpl.php index 214f14adb75..38fc565ac0e 100644 --- a/htdocs/core/tpl/extrafields_view.tpl.php +++ b/htdocs/core/tpl/extrafields_view.tpl.php @@ -201,14 +201,24 @@ if (empty($reshook) && is_array($extrafields->attributes[$object->table_element] print ''; // Convert date into timestamp format - if (in_array($extrafields->attributes[$object->table_element]['type'][$tmpkeyextra], array('date', 'datetime'))) { + if (in_array($extrafields->attributes[$object->table_element]['type'][$tmpkeyextra], array('date'))) { $datenotinstring = $object->array_options['options_'.$tmpkeyextra]; // print 'X'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.'x'; if (!is_numeric($object->array_options['options_'.$tmpkeyextra])) { // For backward compatibility $datenotinstring = $db->jdate($datenotinstring); } //print 'x'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.' - '.dol_print_date($datenotinstring, 'dayhour'); - $value = GETPOSTISSET("options_".$tmpkeyextra) ? dol_mktime(GETPOST("options_".$tmpkeyextra."hour", 'int'), GETPOST("options_".$tmpkeyextra."min", 'int'), 0, GETPOST("options_".$tmpkeyextra."month", 'int'), GETPOST("options_".$tmpkeyextra."day", 'int'), GETPOST("options_".$tmpkeyextra."year", 'int')) : $datenotinstring; + $value = GETPOSTISSET("options_".$tmpkeyextra) ? dol_mktime(12, 0, 0, GETPOST("options_".$tmpkeyextra."month", 'int'), GETPOST("options_".$tmpkeyextra."day", 'int'), GETPOST("options_".$tmpkeyextra."year", 'int')) : $datenotinstring; + } + if (in_array($extrafields->attributes[$object->table_element]['type'][$tmpkeyextra], array('datetime'))) { + $datenotinstring = $object->array_options['options_'.$tmpkeyextra]; + // print 'X'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.'x'; + if (!is_numeric($object->array_options['options_'.$tmpkeyextra])) // For backward compatibility + { + $datenotinstring = $db->jdate($datenotinstring); + } + //print 'x'.$object->array_options['options_' . $tmpkeyextra].'-'.$datenotinstring.' - '.dol_print_date($datenotinstring, 'dayhour'); + $value = GETPOSTISSET("options_".$tmpkeyextra) ? dol_mktime(GETPOST("options_".$tmpkeyextra."hour", 'int'), GETPOST("options_".$tmpkeyextra."min", 'int'), GETPOST("options_".$tmpkeyextra."sec", 'int'), GETPOST("options_".$tmpkeyextra."month", 'int'), GETPOST("options_".$tmpkeyextra."day", 'int'), GETPOST("options_".$tmpkeyextra."year", 'int'), 'tzuserrel') : $datenotinstring; } //TODO Improve element and rights detection diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index 1a223416787..8e9d72d40b4 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -104,10 +104,12 @@ if (($line->info_bits & 2) == 2) { print ''; if ($line->description) { if ($line->description == '(CREDIT_NOTE)' && $line->fk_remise_except > 0) { + include_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; $discount = new DiscountAbsolute($this->db); $discount->fetch($line->fk_remise_except); print ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0)); - } elseif ($line->description == '(DEPOSIT)' && $line->fk_remise_except > 0) { + } elseif ($line->description == '(DEPOSIT)' && $line->fk_remise_except > 0) { + include_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; $discount = new DiscountAbsolute($this->db); $discount->fetch($line->fk_remise_except); print ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0)); @@ -115,11 +117,13 @@ if (($line->info_bits & 2) == 2) { if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) { print ' ('.dol_print_date($discount->datec).')'; } - } elseif ($line->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) { + } elseif ($line->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) { + include_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; $discount = new DiscountAbsolute($this->db); $discount->fetch($line->fk_remise_except); print ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0)); } elseif ($line->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) { + include_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php'; $discount = new DiscountAbsolute($this->db); $discount->fetch($line->fk_remise_except); print ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0)); diff --git a/htdocs/cron/list.php b/htdocs/cron/list.php index dba828e97b2..0a3b19734e1 100644 --- a/htdocs/cron/list.php +++ b/htdocs/cron/list.php @@ -545,13 +545,13 @@ if ($num > 0) { print ''; if (!empty($obj->datestart)) { - print dol_print_date($db->jdate($obj->datestart), 'dayhour'); + print dol_print_date($db->jdate($obj->datestart), 'dayhour', 'tzserver'); } print ''; print ''; if (!empty($obj->dateend)) { - print dol_print_date($db->jdate($obj->dateend), 'dayhour'); + print dol_print_date($db->jdate($obj->dateend), 'dayhour', 'tzserver'); } print ''; @@ -569,7 +569,7 @@ if ($num > 0) { // Date start last run print ''; if (!empty($datelastrun)) { - print dol_print_date($datelastrun, 'dayhoursec'); + print dol_print_date($datelastrun, 'dayhoursec', 'tzserver'); } print ''; diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 1b723cf716d..b50589b6ad4 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1009,16 +1009,7 @@ if ($action == 'create') { $i++; } print '}); - jQuery("#autoreset").click(function() { console.log("Reset values to 0"); '; - $i = 0; - while ($i < $numAsked) { - print 'jQuery("#qtyl'.$i.'").val(0);'."\n"; - if (!empty($conf->productbatch->enabled)) { - print 'jQuery("#qtyl'.$i.'_'.$i.'").val(0);'."\n"; - } - $i++; - } - print '}); + jQuery("#autoreset").click(function() { console.log("Reset values to 0"); jQuery(".qtyl").val(0); }); }); '; @@ -1252,7 +1243,7 @@ if ($action == 'create') { $deliverableQty = min($quantityToBeDelivered, $batchStock); print ''; print ''; - print ''; + print ''; print ''; print ''; @@ -1284,7 +1275,7 @@ if ($action == 'create') { } else { print ''; print ''; - print ' '; + print ' '; print ''; print ''; @@ -1395,7 +1386,7 @@ if ($action == 'create') { $deliverableQty = 0; } print ''; - print ''; + print ''; print ''; print ''; @@ -1439,7 +1430,7 @@ if ($action == 'create') { if ($warehouse_selected_id <= 0) { // We did not force a given warehouse, so we won't have no warehouse to change qty. $disabled = 'disabled="disabled"'; } - print ' '; + print ' '; } else { print $langs->trans("NA"); } @@ -2141,7 +2132,7 @@ if ($action == 'create') { foreach ($lines[$i]->detail_batch as $detail_batch) { print ''; // Qty to ship or shipped - print ''; + print ''; // Batch number managment if ($lines[$i]->entrepot_id == 0) { // only show lot numbers from src warehouse when shipping from multiple warehouses @@ -2153,7 +2144,7 @@ if ($action == 'create') { // add a 0 qty lot row to be able to add a lot print ''; // Qty to ship or shipped - print ''; + print ''; // Batch number managment print ''.$formproduct->selectLotStock('', 'batchl'.$line_id.'_0', '', 1, 0, $lines[$i]->fk_product).''; print ''; @@ -2163,7 +2154,7 @@ if ($action == 'create') { print ''; print ''; // Qty to ship or shipped - print ''; + print ''; // Warehouse source print ''.$formproduct->selectWarehouses($lines[$i]->entrepot_id, 'entl'.$line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).''; // Batch number managment @@ -2174,7 +2165,7 @@ if ($action == 'create') { foreach ($lines[$i]->details_entrepot as $detail_entrepot) { print ''; // Qty to ship or shipped - print ''; + print ''; // Warehouse source print ''.$formproduct->selectWarehouses($detail_entrepot->entrepot_id, 'entl'.$detail_entrepot->line_id, '', 1, 0, $lines[$i]->fk_product, '', 1).''; // Batch number managment @@ -2189,7 +2180,7 @@ if ($action == 'create') { print ''; print ''; // Qty to ship or shipped - print ''; + print ''; // Warehouse source print ''; // Batch number managment diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 9e56c5f5c3a..0fd3ab0b2a6 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -291,4 +291,5 @@ WarningSomeBankTransactionByChequeWereRemovedAfter=Some bank transaction were re WarningFailedToAddFileIntoDatabaseIndex=Warning, failed to add file entry into ECM database index table WarningTheHiddenOptionIsOn=Warning, the hidden option %s is on. WarningCreateSubAccounts=Warning, you can't create directly a sub account, you must create a third party or an user and assign them an accounting code to find them in this list -WarningAvailableOnlyForHTTPSServers=Available only if using HTTPS secured connection. \ No newline at end of file +WarningAvailableOnlyForHTTPSServers=Available only if using HTTPS secured connection. +WarningModuleXDisabledSoYouMayMissEventHere=Module %s has not been enabled. So you may miss a lot of event here. \ No newline at end of file diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index 3bad9a8a854..b22a6c389dd 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -96,7 +96,7 @@ class Mo extends CommonObject 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>"Id",), 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'position'=>5, 'notnull'=>1, 'default'=>'1', 'index'=>1), 'ref' => array('type'=>'varchar(128)', 'label'=>'Ref', 'enabled'=>1, 'visible'=>4, 'position'=>10, 'notnull'=>1, 'default'=>'(PROV)', 'index'=>1, 'searchall'=>1, 'comment'=>"Reference of object", 'showoncombobox'=>'1', 'noteditable'=>1), - 'fk_bom' => array('type'=>'integer:Bom:bom/class/bom.class.php:0:t.status=1', 'filter'=>'active=1', 'label'=>'BOM', 'enabled'=>1, 'visible'=>1, 'position'=>33, 'notnull'=>-1, 'index'=>1, 'comment'=>"Original BOM", 'css'=>'maxwidth300'), + 'fk_bom' => array('type'=>'integer:Bom:bom/class/bom.class.php:0:t.status=1', 'filter'=>'active=1', 'label'=>'BOM', 'enabled'=>1, 'visible'=>1, 'position'=>33, 'notnull'=>-1, 'index'=>1, 'comment'=>"Original BOM", 'css'=>'minwidth100 maxwidth300'), 'fk_product' => array('type'=>'integer:Product:product/class/product.class.php:0', 'label'=>'Product', 'enabled'=>1, 'visible'=>1, 'position'=>35, 'notnull'=>1, 'index'=>1, 'comment'=>"Product to produce", 'css'=>'maxwidth300', 'picto'=>'product'), 'qty' => array('type'=>'real', 'label'=>'QtyToProduce', 'enabled'=>1, 'visible'=>1, 'position'=>40, 'notnull'=>1, 'comment'=>"Qty to produce", 'css'=>'width75', 'default'=>1, 'isameasure'=>1), 'label' => array('type'=>'varchar(255)', 'label'=>'Label', 'enabled'=>1, 'visible'=>1, 'position'=>42, 'notnull'=>-1, 'searchall'=>1, 'showoncombobox'=>'1',), diff --git a/htdocs/mrp/mo_list.php b/htdocs/mrp/mo_list.php index ed78c46f133..89292973214 100644 --- a/htdocs/mrp/mo_list.php +++ b/htdocs/mrp/mo_list.php @@ -76,7 +76,7 @@ $search_array_options = $extrafields->getOptionalsFromPost($object->table_elemen // Default sort order (if not yet defined by previous GETPOST) if (!$sortfield) { - $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition. + $sortfield = "t.ref"; // Set here default search field. By default 1st field in definition. } if (!$sortorder) { $sortorder = "ASC"; diff --git a/htdocs/product/stock/productlot_card.php b/htdocs/product/stock/productlot_card.php index 6aacdca2b6c..32c7f7c6ee3 100644 --- a/htdocs/product/stock/productlot_card.php +++ b/htdocs/product/stock/productlot_card.php @@ -133,18 +133,24 @@ if (empty($reshook)) { $backurlforlist = dol_buildpath('/product/stock/productlot_list.php', 1); if ($action == 'seteatby' && $user->rights->stock->creer) { - $newvalue = dol_mktime(12, 0, 0, $_POST['eatbymonth'], $_POST['eatbyday'], $_POST['eatbyyear']); + $newvalue = dol_mktime(12, 0, 0, GETPOST('eatbymonth', 'int'), GETPOST('eatbyday', 'int'), GETPOST('eatbyyear', 'int')); $result = $object->setValueFrom('eatby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); if ($result < 0) { - dol_print_error($db, $object->error); + setEventMessages($object->error, null, 'errors'); + $action == 'editeatby'; + } else { + $action = 'view'; } } if ($action == 'setsellby' && $user->rights->stock->creer) { - $newvalue = dol_mktime(12, 0, 0, $_POST['sellbymonth'], $_POST['sellbyday'], $_POST['sellbyyear']); + $newvalue = dol_mktime(12, 0, 0, GETPOST('sellbymonth', 'int'), GETPOST('sellbyday', 'int'), GETPOST('sellbyyear', 'int')); $result = $object->setValueFrom('sellby', $newvalue, '', null, 'date', '', $user, 'PRODUCTLOT_MODIFY'); if ($result < 0) { - dol_print_error($db, $object->error); + setEventMessages($object->error, null, 'errors'); + $action == 'editsellby'; + } else { + $action = 'view'; } } @@ -172,8 +178,9 @@ if (empty($reshook)) { } } - if ($error) + if ($error) { $action = 'edit_extras'; + } } // Action to add record @@ -415,7 +422,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''; } - // Other attributes. Fields from hook formObjectOptions and Extrafields. + // Other attributes include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; print ''; diff --git a/htdocs/public/emailing/mailing-read.php b/htdocs/public/emailing/mailing-read.php index 929433d88e0..454201203cc 100644 --- a/htdocs/public/emailing/mailing-read.php +++ b/htdocs/public/emailing/mailing-read.php @@ -46,6 +46,9 @@ if (!defined('NOREQUIREMENU')) { if (!defined('NOIPCHECK')) { define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip } +if (!defined("NOSESSION")) { + define("NOSESSION", '1'); +} /** * Header empty @@ -67,6 +70,8 @@ function llxFooter() require '../../main.inc.php'; +$mtid = GETPOST('mtid'); +$email = GETPOST('email'); $tag = GETPOST('tag'); $securitykey = GETPOST('securitykey'); @@ -83,23 +88,55 @@ if ($securitykey != $conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY) { } if (!empty($tag)) { - $statut = '2'; - $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".$statut." WHERE tag='".$db->escape($tag)."'"; - dol_syslog("public/emailing/mailing-read.php : Mail read : ".$sql, LOG_DEBUG); + dol_syslog("public/emailing/mailing-read.php : Update status of email target and thirdparty for tag ".$tag, LOG_DEBUG); + + $sql = "SELECT mc.rowid, mc.email, mc.statut, mc.source_type, mc.source_id, m.entity"; + $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m"; + $sql .= " WHERE mc.fk_mailing = m.rowid AND mc.tag='".$db->escape($tag)."'"; $resql = $db->query($sql); + if (!$resql) dol_print_error($db); + + $obj = $db->fetch_object($resql); + + if (empty($obj)) { + print 'Email target not valid. Operation canceled.'; + exit; + } + if (empty($obj->email)) { + print 'Email target not valid. Operation canceled.'; + exit; + } + if ($obj->statut == 2 || $obj->statut == 3) { + print 'Email target already set to read or unsubscribe. Operation canceled.'; + exit; + } + // TODO Test that mtid and email match also with the one found from $tag + /* + if ($obj->email != $email) + { + print 'Email does not match tagnot found. No need to unsubscribe.'; + exit; + } + */ + + //Update status of target + $statut = '2'; + $sql = "UPDATE ".MAIN_DB_PREFIX."mailing_cibles SET statut=".$statut." WHERE rowid = ".((int) $obj->rowid); + $resql = $db->query($sql); + if (!$resql) dol_print_error($db); //Update status communication of thirdparty prospect - $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=3 WHERE fk_stcomm != -1 AND rowid IN (SELECT source_id FROM ".MAIN_DB_PREFIX."mailing_cibles WHERE tag='".$db->escape($tag)."' AND source_type='thirdparty' AND source_id is not null)"; - dol_syslog("public/emailing/mailing-read.php : Mail read thirdparty : ".$sql, LOG_DEBUG); - - $resql = $db->query($sql); + if ($obj->source_id > 0 && $obj->source_type == 'thirdparty' && $obj->entity) { + $sql = "UPDATE ".MAIN_DB_PREFIX.'societe SET fk_stcomm = 3 WHERE fk_stcomm <> -1 AND entity = '.$obj->entity.' AND rowid = '.$obj->source_id; + $resql = $db->query($sql); + } //Update status communication of contact prospect - $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET fk_stcomm=3 WHERE fk_stcomm != -1 AND rowid IN (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."socpeople AS sc INNER JOIN ".MAIN_DB_PREFIX."mailing_cibles AS mc ON mc.tag = '".$db->escape($tag)."' AND mc.source_type = 'contact' AND mc.source_id = sc.rowid)"; - dol_syslog("public/emailing/mailing-read.php : Mail read contact : ".$sql, LOG_DEBUG); - - $resql = $db->query($sql); + if ($obj->source_id > 0 && $obj->source_type == 'contact' && $obj->entity) { + $sql = "UPDATE ".MAIN_DB_PREFIX.'societe SET fk_stcomm = 3 WHERE fk_stcomm <> -1 AND entity = '.$obj->entity.' AND rowid IN (SELECT sc.fk_soc FROM '.MAIN_DB_PREFIX.'socpeople AS sc WHERE sc.rowid = '.$obj->source_id.')'; + $resql = $db->query($sql); + } } $db->close(); diff --git a/htdocs/public/emailing/mailing-unsubscribe.php b/htdocs/public/emailing/mailing-unsubscribe.php index 2ef939675cf..9c39dafa18d 100644 --- a/htdocs/public/emailing/mailing-unsubscribe.php +++ b/htdocs/public/emailing/mailing-unsubscribe.php @@ -42,6 +42,9 @@ if (!defined('NOREQUIREMENU')) { if (!defined('NOIPCHECK')) { define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip } +if (!defined("NOSESSION")) { + define("NOSESSION", '1'); +} /** * Header empty @@ -68,6 +71,8 @@ global $user, $conf, $langs; $langs->loadLangs(array("main", "mails")); +$mtid = GETPOST('mtid'); +$email = GETPOST('email'); $tag = GETPOST('tag'); $unsuscrib = GETPOST('unsuscrib'); $securitykey = GETPOST('securitykey'); @@ -88,7 +93,7 @@ if ($securitykey != $conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY) { if (!empty($tag) && ($unsuscrib == '1')) { dol_syslog("public/emailing/mailing-unsubscribe.php : Launch unsubscribe requests", LOG_DEBUG); - $sql = "SELECT mc.email, m.entity"; + $sql = "SELECT mc.rowid, mc.email, mc.statut, m.entity"; $sql .= " FROM ".MAIN_DB_PREFIX."mailing_cibles as mc, ".MAIN_DB_PREFIX."mailing as m"; $sql .= " WHERE mc.fk_mailing = m.rowid AND mc.tag='".$db->escape($tag)."'"; @@ -99,10 +104,26 @@ if (!empty($tag) && ($unsuscrib == '1')) { $obj = $db->fetch_object($resql); - if (empty($obj->email)) { - print 'Email not found. No need to unsubscribe.'; + if (empty($obj)) { + print 'Email target not valid. Operation canceled.'; exit; } + if (empty($obj->email)) { + print 'Email target not valid. Operation canceled.'; + exit; + } + if ($obj->statut == 3) { + print 'Email target already set to unsubscribe. Operation canceled.'; + exit; + } + // TODO Test that mtid and email match also with the one found from $tag + /* + if ($obj->email != $email) + { + print 'Email does not match tagnot found. No need to unsubscribe.'; + exit; + } + */ // Update status of mail in recipient mailing list table $statut = '3'; @@ -128,7 +149,7 @@ if (!empty($tag) && ($unsuscrib == '1')) { */ // Update status communication of email (new usage) - $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe (date_creat, entity, email) VALUES ('".$db->idate(dol_now())."', ".$db->escape($obj->entity).", '".$db->escape($obj->email)."')"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."mailing_unsubscribe (date_creat, entity, email, unsubscribegroup, ip) VALUES ('".$db->idate(dol_now())."', ".$db->escape($obj->entity).", '".$db->escape($obj->email)."', '', '".$db->escape(getUserRemoteIP())."')"; $resql = $db->query($sql); //if (! $resql) dol_print_error($db); No test on errors, may fail if already unsubscribed diff --git a/test/phpunit/FactureRecTest.php b/test/phpunit/FactureRecTest.php index 2a0b8823973..a6e91695782 100644 --- a/test/phpunit/FactureRecTest.php +++ b/test/phpunit/FactureRecTest.php @@ -126,14 +126,15 @@ class FactureRecTest extends PHPUnit\Framework\TestCase print __METHOD__."\n"; } - /** - * testFactureCreate - * - * @return int - */ - public function testFactureRecCreate() - { - global $conf,$user,$langs,$db; + /** + * testFactureRecCreate + * + * @return int + */ + public function testFactureRecCreate() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; @@ -141,36 +142,66 @@ class FactureRecTest extends PHPUnit\Framework\TestCase $localobjectinv=new Facture($this->savdb); $localobjectinv->initAsSpecimen(); - $localobjectinv->create($user); + $result = $localobjectinv->create($user); + + print __METHOD__." result=".$result."\n"; $localobject=new FactureRec($this->savdb); - $localobject->initAsSpecimen(); - $result=$localobject->create($user, $localobjectinv->id); + $localobject->initAsSpecimen(); + $result = $localobject->create($user, $localobjectinv->id); - $this->assertLessThan($result, 0); - print __METHOD__." result=".$result."\n"; - return $result; - } + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result, 'Create recurring invoice from common invoice'); - /** - * Edit an object to test updates - * - * @param Facture $localobject Object Facture - * @return void - */ - public function changeProperties(&$localobject) - { - $localobject->note_private='New note'; - //$localobject->note='New note after update'; - } + return $result; + } - /** - * Compare all public properties values of 2 objects - * - * @param Object $oA Object operand 1 - * @param Object $oB Object operand 2 - * @param boolean $ignoretype False will not report diff if type of value differs - * @param array $fieldstoignorearray Array of fields to ignore in diff + /** + * testFactureRecFetch + * + * @param int $id Id of created recuriing invoice + * @return int + * + * @depends testFactureRecCreate + * The depends says test is run only if previous is ok + */ + public function testFactureRecFetch($id) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $localobject=new FactureRec($this->savdb); + $result = $localobject->fetch($id); + + print __METHOD__." result=".$result."\n"; + $this->assertGreaterThan(0, $result); + return $result; + } + + + + /** + * Edit an object to test updates + * + * @param FactureRec $localobject Object Facture rec + * @return void + */ + public function changeProperties(&$localobject) + { + $localobject->note_private='New note'; + //$localobject->note='New note after update'; + } + + /** + * Compare all public properties values of 2 objects + * + * @param Object $oA Object operand 1 + * @param Object $oB Object operand 2 + * @param boolean $ignoretype False will not report diff if type of value differs + * @param array $fieldstoignorearray Array of fields to ignore in diff * @return array Array with differences */ public function objCompare($oA, $oB, $ignoretype = true, $fieldstoignorearray = array('id'))