diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index a641ccb4db5..344a45f19fc 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -538,7 +538,7 @@ class AccountancyExport //print substr(length_accountg($line->numero_compte), 0, 2) . $separator; print '"'.dol_trunc($line->label_operation, 40, 'right', 'UTF-8', 1).'"' . $separator; print '"'.dol_trunc($line->piece_num, 15, 'right', 'UTF-8', 1).'"'.$separator; - print price2num($line->montant).$separator; + print price2num(abs($line->montant)).$separator; print $line->sens.$separator; print $date . $separator; //print 'EUR'; diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index e8da06ee2ca..511a7d8b70d 100755 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -1391,7 +1391,7 @@ if (empty($reshook)) $desc=(! empty($lines[$i]->desc)?$lines[$i]->desc:$lines[$i]->libelle); if ($object->situation_counter == 1) $lines[$i]->situation_percent = 0; - if ($lines[$i]->subprice < 0) + if ($lines[$i]->subprice < 0 && empty($conf->global->INVOICE_KEEP_DISCOUNT_LINES_AS_IN_ORIGIN)) { // Negative line, we create a discount line $discount = new DiscountAbsolute($db); @@ -2588,22 +2588,47 @@ if ($action == 'create') if (empty($socid)) $soc = $objectsrc->thirdparty; - $cond_reglement_id = (! empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(! empty($soc->cond_reglement_id)?$soc->cond_reglement_id:0)); - $mode_reglement_id = (! empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(! empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); - $fk_account = (! empty($objectsrc->fk_account)?$objectsrc->fk_account:(! empty($soc->fk_account)?$soc->fk_account:0)); - $remise_percent = (! empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(! empty($soc->remise_percent)?$soc->remise_percent:0)); - $remise_absolue = (! empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(! empty($soc->remise_absolue)?$soc->remise_absolue:0)); - $dateinvoice = (empty($dateinvoice)?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$dateinvoice); + $dateinvoice = (empty($dateinvoice)?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:''):$dateinvoice); - if (!empty($conf->multicurrency->enabled)) - { - if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code; - if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx; + if ($element == 'expedition') { + $ref_client = (! empty($objectsrc->ref_customer)?$objectsrc->ref_customer:''); + + $elem = $subelem = $objectsrc->origin; + $expeoriginid = $objectsrc->origin_id; + dol_include_once('/'.$elem.'/class/'.$subelem.'.class.php'); + $classname = ucfirst($subelem); + + $expesrc = new $classname($db); + $expesrc->fetch($expeoriginid); + + $cond_reglement_id = (! empty($expesrc->cond_reglement_id)?$expesrc->cond_reglement_id:(! empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1)); + $mode_reglement_id = (! empty($expesrc->mode_reglement_id)?$expesrc->mode_reglement_id:(! empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); + $fk_account = (! empty($expesrc->fk_account)?$expesrc->fk_account:(! empty($soc->fk_account)?$soc->fk_account:0)); + $remise_percent = (! empty($expesrc->remise_percent)?$expesrc->remise_percent:(! empty($soc->remise_percent)?$soc->remise_percent:0)); + $remise_absolue = (! empty($expesrc->remise_absolue)?$expesrc->remise_absolue:(! empty($soc->remise_absolue)?$soc->remise_absolue:0)); + + //Replicate extrafields + $expesrc->fetch_optionals($expeoriginid); + $object->array_options=$expesrc->array_options; } + else + { + $cond_reglement_id = (! empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(! empty($soc->cond_reglement_id)?$soc->cond_reglement_id:0)); + $mode_reglement_id = (! empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(! empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0)); + $fk_account = (! empty($objectsrc->fk_account)?$objectsrc->fk_account:(! empty($soc->fk_account)?$soc->fk_account:0)); + $remise_percent = (! empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(! empty($soc->remise_percent)?$soc->remise_percent:0)); + $remise_absolue = (! empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(! empty($soc->remise_absolue)?$soc->remise_absolue:0)); - // Replicate extrafields - $objectsrc->fetch_optionals($originid); - $object->array_options = $objectsrc->array_options; + if (!empty($conf->multicurrency->enabled)) + { + if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code; + if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) $currency_tx = $objectsrc->multicurrency_tx; + } + + // Replicate extrafields + $objectsrc->fetch_optionals($originid); + $object->array_options = $objectsrc->array_options; + } } } else diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index a41f8aaf93c..0744f93435a 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -82,6 +82,7 @@ $search_montant_localtax2=GETPOST('search_montant_localtax2', 'alpha'); $search_montant_ttc=GETPOST('search_montant_ttc', 'alpha'); $search_status=GETPOST('search_status', 'intcomma'); $search_paymentmode=GETPOST('search_paymentmode', 'int'); +$search_paymentterms=GETPOST('search_paymentterms', 'int'); $search_town=GETPOST('search_town', 'alpha'); $search_zip=GETPOST('search_zip', 'alpha'); $search_state=trim(GETPOST("search_state")); @@ -162,6 +163,7 @@ $arrayfields=array( 'country.code_iso'=>array('label'=>"Country", 'checked'=>0), 'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers), 'f.fk_mode_reglement'=>array('label'=>"PaymentMode", 'checked'=>1), + 'f.fk_cond_reglement'=>array('label'=>"PaymentConditionsShort", 'checked'=>1), 'f.total_ht'=>array('label'=>"AmountHT", 'checked'=>1), 'f.total_vat'=>array('label'=>"AmountVAT", 'checked'=>0), 'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>($mysoc->localtax1_assuj=="1")), @@ -214,6 +216,7 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', $search_montant_ttc=''; $search_status=''; $search_paymentmode=''; + $search_paymentterms=''; $search_town=''; $search_zip=""; $search_state=""; @@ -359,7 +362,7 @@ $thirdpartystatic=new Societe($db); $sql = 'SELECT'; if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; -$sql.= ' f.rowid as id, f.ref, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,'; +$sql.= ' f.rowid as id, f.ref, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.fk_cond_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,'; $sql.= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,'; $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,'; $sql.= ' f.paye as paye, f.fk_statut,'; @@ -451,6 +454,7 @@ if ($search_status != '-1' && $search_status != '') } } if ($search_paymentmode > 0) $sql .= " AND f.fk_mode_reglement = ".$db->escape($search_paymentmode); +if ($search_paymentterms > 0) $sql .= " AND f.fk_cond_reglement = ".$db->escape($search_paymentterms); $sql.= dolSqlDateFilter("f.datef", $search_day, $search_month, $search_year); $sql.= dolSqlDateFilter("f.date_lim_reglement", $search_day_lim, $search_month_lim, $search_year_lim); if ($option == 'late') $sql.=" AND f.date_lim_reglement < '".$db->idate(dol_now() - $conf->facture->client->warning_delay)."'"; @@ -468,7 +472,7 @@ $sql.=$hookmanager->resPrint; if (! $sall) { - $sql.= ' GROUP BY f.rowid, f.ref, ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total, f.tva, f.total_ttc,'; + $sql.= ' GROUP BY f.rowid, f.ref, ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.fk_cond_reglement, f.total, f.tva, f.total_ttc,'; $sql.= ' f.localtax1, f.localtax2,'; $sql.= ' f.datef, f.date_lim_reglement,'; $sql.= ' f.paye, f.fk_statut,'; @@ -562,6 +566,7 @@ if ($resql) if ($search_montant_ttc != '') $param.='&search_montant_ttc='.urlencode($search_montant_ttc); if ($search_status != '') $param.='&search_status='.urlencode($search_status); if ($search_paymentmode > 0) $param.='&search_paymentmode='.urlencode($search_paymentmode); + if ($search_paymentterms > 0) $param.='&search_paymentterms='.urlencode($search_paymentterms); if ($show_files) $param.='&show_files='.urlencode($show_files); if ($option) $param.="&search_option=".urlencode($option); if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); @@ -777,6 +782,13 @@ if ($resql) $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 1, 1, 10); print ''; } + // Payment terms + if (! empty($arrayfields['f.fk_cond_reglement']['checked'])) + { + print ''; + $form->select_conditions_paiements($search_paymentterms, 'search_paymentterms', -1, 1, 1); + print ''; + } if (! empty($arrayfields['f.total_ht']['checked'])) { // Amount @@ -870,6 +882,7 @@ if ($resql) if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, 'align="center"', $sortfield, $sortorder); if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, 'align="center"', $sortfield, $sortorder); if (! empty($arrayfields['f.fk_mode_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_mode_reglement", "", $param, "", $sortfield, $sortorder); + if (! empty($arrayfields['f.fk_cond_reglement']['checked'])) print_liste_field_titre($arrayfields['f.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "f.fk_cond_reglement", "", $param, "", $sortfield, $sortorder); if (! empty($arrayfields['f.total_ht']['checked'])) print_liste_field_titre($arrayfields['f.total_ht']['label'], $_SERVER['PHP_SELF'], 'f.total', '', $param, 'class="right"', $sortfield, $sortorder); if (! empty($arrayfields['f.total_vat']['checked'])) print_liste_field_titre($arrayfields['f.total_vat']['label'], $_SERVER['PHP_SELF'], 'f.tva', '', $param, 'class="right"', $sortfield, $sortorder); if (! empty($arrayfields['f.total_localtax1']['checked'])) print_liste_field_titre($arrayfields['f.total_localtax1']['label'], $_SERVER['PHP_SELF'], 'f.localtax1', '', $param, 'class="right"', $sortfield, $sortorder); @@ -1082,6 +1095,15 @@ if ($resql) if (! $i) $totalarray['nbfield']++; } + // Payment terms + if (! empty($arrayfields['f.fk_cond_reglement']['checked'])) + { + print ''; + $form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none'); + print ''; + if (! $i) $totalarray['nbfield']++; + } + // Amount HT if (! empty($arrayfields['f.total_ht']['checked'])) { diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 398640ffb64..d350c8b3ff3 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -5,7 +5,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2008 Raphael Bertrand (Resultic) - * Copyright (C) 2013 Florian Henry + * Copyright (C) 2013 Florian Henry * Copyright (C) 2013 Alexandre Spangaro * Copyright (C) 2013 Juanjo Menent * Copyright (C) 2015 Marcos García @@ -81,6 +81,7 @@ class Contact extends CommonObject public $civility_id; // In fact we store civility_code public $civility_code; + public $civility; public $address; public $zip; public $town; @@ -695,6 +696,8 @@ class Contact extends CommonObject { global $langs; + $langs->load("dict"); + dol_syslog(get_class($this)."::fetch id=".$id, LOG_DEBUG); if (empty($id) && empty($ref_ext)) @@ -705,7 +708,7 @@ class Contact extends CommonObject $langs->load("companies"); - $sql = "SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_id, c.lastname, c.firstname,"; + $sql = "SELECT c.rowid, c.entity, c.fk_soc, c.ref_ext, c.civility as civility_code, c.lastname, c.firstname,"; $sql.= " c.address, c.statut, c.zip, c.town,"; $sql.= " c.fk_pays as country_id,"; $sql.= " c.fk_departement as state_id,"; @@ -747,10 +750,12 @@ class Contact extends CommonObject $this->entity = $obj->entity; $this->ref = $obj->rowid; $this->ref_ext = $obj->ref_ext; - $this->civility_id = $obj->civility_id; - $this->civility_code = $obj->civility_id; - $this->lastname = $obj->lastname; - $this->firstname = $obj->firstname; + + $this->civility_code = $obj->civility_code; + $this->civility = $obj->civility_code?($langs->trans("Civility".$obj->civility_code) != ("Civility".$obj->civility_code) ? $langs->trans("Civility".$obj->civility_code) : $obj->civility_code):''; + + $this->lastname = $obj->lastname; + $this->firstname = $obj->firstname; $this->address = $obj->address; $this->zip = $obj->zip; $this->town = $obj->town; @@ -766,23 +771,23 @@ class Contact extends CommonObject $this->country_code = $obj->country_id?$obj->country_code:''; $this->country = $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):''; - $this->socid = $obj->fk_soc; + $this->socid = $obj->fk_soc; $this->socname = $obj->socname; - $this->poste = $obj->poste; + $this->poste = $obj->poste; $this->statut = $obj->statut; - $this->phone_pro = trim($obj->phone); + $this->phone_pro = trim($obj->phone); $this->fax = trim($obj->fax); $this->phone_perso = trim($obj->phone_perso); $this->phone_mobile = trim($obj->phone_mobile); - $this->email = $obj->email; + $this->email = $obj->email; $this->jabberid = $obj->jabberid; - $this->skype = $obj->skype; - $this->twitter = $obj->twitter; - $this->facebook = $obj->facebook; - $this->linkedin = $obj->linkedin; - $this->photo = $obj->photo; + $this->skype = $obj->skype; + $this->twitter = $obj->twitter; + $this->facebook = $obj->facebook; + $this->linkedin = $obj->linkedin; + $this->photo = $obj->photo; $this->priv = $obj->priv; $this->mail = $obj->email; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index c84c501ad21..4b25d23b882 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -6346,7 +6346,7 @@ class Form