diff --git a/.travis.yml b/.travis.yml index ca2574bc846..5bc5f49b2e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -128,7 +128,7 @@ script: - php upgrade.php 3.6.0 3.7.0 ignoredbversion > upgrade360370.log - php upgrade2.php 3.6.0 3.7.0 ignoredbversion > upgrade360370-2.log - php upgrade.php 3.7.0 3.8.0 ignoredbversion > upgrade370380.log - - cat upgrade370380.log +# - cat upgrade370380.log - php upgrade2.php 3.7.0 3.8.0 ignoredbversion > upgrade370380-2.log # - cat upgrade370380-2.log - cd ../.. diff --git a/ChangeLog b/ChangeLog index 68d6b1848f1..98339d3874a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,16 +41,34 @@ Dolibarr better: - Hooks 'printLeftBlock' and 'formConfirm' are now compliant with hook development rules. They are "addreplace" hooks, so you must return content with "->resprints='mycontent'" and not with "return 'mycontent'" - All fields "fk_societe" were renamed into "fk_soc". +- Method select_PriceBaseType and load_PriceBaseType were merged into selectPriceBaseType ***** ChangeLog for 3.7.1 compared to 3.7.* ***** -- Fix: Bug in the new photo system -- Fix: Error management -- Fix: [ Bug #2714 ] Members -> Memberxy-> Agenda -> technical Error -- Fix: [ Bug #2713 ] 3.7.0 mailing-unsubscribe.php not unsubscribe +FIX Bug in the new photo system +FIX Error management +FIX [ Bug #2714 ] Members -> Memberxy-> Agenda -> technical Error +FIX [ Bug #2713 ] 3.7.0 mailing-unsubscribe.php not unsubscribe +FIX #2901 +FIX when we create an agenda event with "Not applicable" status, it is automatically saved with "To do" status +FIX check the user status during authentication +FIX top links menu have target attribute with wrong value +FIX extrafields required on thirdparty +FIX create contact with extrafield is null when it is require +FIX width multiselect +FIX "script" tag with wrong syntax +Fix bug debian 786479 +FIX update usergroup name +Fix facturestats was not filtering on invoice type +FIX #2856 : Wrong table design +FIX button create payment hide if tax amount is less than 1 +FIX event for restricted user was restricted if company null +FIX send mail, copy sendto don't read the list of contact +FIX Properly escape untrusted data to prevent HTML injection. +FIX send mail, copy sendto don't read the list of contact -- Path to save photos of products was moved in 3.7.0 to match path of other attached files. If you had loose - your photo on the photo tab of products, you can set the constant "PRODUCT_USE_OLD_PATH_FOR_PHOTO" to - restore old path. +Path to save photos of products was moved in 3.7.0 to match path of other attached files. If you had loose +your photo on the photo tab of products, you can set the constant "PRODUCT_USE_OLD_PATH_FOR_PHOTO" to +restore old path. WARNING: @@ -236,8 +254,8 @@ Dolibarr better: - Table llx_c_pays were renamed into llx_c_country. - Triggers *_BUILDDOC are removed. Building a doc is not a business event. For action after creation of a pdf or odt, hook "afterPDFCreation" or "afterODTCreation" must be used instead. -- A lot of pages called fiche.php were renamed into card.php -- A lot of pages called liste.php were renamed into list.php +- A lot of pages named fiche.php were renamed into card.php +- A lot of pages named liste.php were renamed into list.php - If you used warehouse/stock module, recheck setup of stock increase/decrease rules of the warehouse module and your Point Of Sale module setup if you use one. - Replaced USER_UPDATE_SESSION trigger with an updateSession hook may break modules using it. diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl index c667754d4ab..bdfc9d8972a 100755 --- a/build/makepack-dolibarr.pl +++ b/build/makepack-dolibarr.pl @@ -455,8 +455,9 @@ if ($nboftargetok) { $ret=`rm -fr $BUILDROOT/$PROJECT/documents`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/document`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/documents`; - # Removed known external modules to avoir any error when packaging on test env + # Removed known external modules to avoid any error when packaging from env where external modules are tested $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/ancotec*`; + $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/cabinetmed*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/calling*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/bootstrap*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/custom*`; @@ -981,10 +982,10 @@ if ($nboftargetok) { mkdir($DESTI.'/package_windows'); if (-d $DESTI.'/package_windows') { $NEWDESTI=$DESTI.'/package_windows'; } - print "Remove target $FILENAMEEXEDOLIWAMP.exe...\n"; + print "Remove target $NEWDESTI/$FILENAMEEXEDOLIWAMP.exe...\n"; unlink "$NEWDESTI/$FILENAMEEXEDOLIWAMP.exe"; - print "Check that in your Wine setup, you create a Z: drive that point to your /tmp directory.\n"; + print "Check that in your Wine setup, you create a Z: drive that point to your / directory.\n"; $SOURCEBACK=$SOURCE; $SOURCEBACK =~ s/\//\\/g; diff --git a/build/makepack-howto.txt b/build/makepack-howto.txt index 7f814a826df..2cc29a14a9a 100644 --- a/build/makepack-howto.txt +++ b/build/makepack-howto.txt @@ -8,7 +8,7 @@ This files describe steps made by Dolibarr packaging team to make a beta version of Dolibarr, step by step. - Check all files are commited. -- Update version/info in ChangeLog. To generate a changelog, you can do "git log `git merge-base x.y origin/develop`..x.y --no-merges --pretty=short --oneline | sed -e "s/^[0-9a-z]* //" | grep -i -e '^FIX\|NEW'" +- Update version/info in ChangeLog. To generate a changelog, you can do "git log `git merge-base (x.y)-1 origin/develop`..x.y(.z) --no-merges --pretty=short --oneline | sed -e "s/^[0-9a-z]* //" | grep -i -e '^FIX\|NEW'" - Update version number with x.y.z-w in htdocs/filefunc.inc.php - Update version number with x.y.z-w in build/debian/changelog - Commit all changes. @@ -29,7 +29,7 @@ This files describe steps made by Dolibarr packaging team to make a complete release of Dolibarr, step by step. - Check all files are commited. -- Update version/info in ChangeLog. To generate a changelog, you can do "git log `git merge-base x.y origin/develop`..x.y --no-merges --pretty=short --oneline | sed -e "s/^[0-9a-z]* //" | grep -i -e '^FIX\|NEW'" +- Update version/info in ChangeLog. To generate a changelog, you can do "git log `git merge-base (x.y)-1 origin/develop`..x.y(.z) --no-merges --pretty=short --oneline | sed -e "s/^[0-9a-z]* //" | grep -i -e '^FIX\|NEW'" - Update version number with x.y.z in htdocs/filefunc.inc.php - Update version number with x.y.z in build/debian/changelog - Commit all changes. diff --git a/dev/ansible/README.md b/dev/ansible/README.md index aeed9fc6983..e498ebc3340 100644 --- a/dev/ansible/README.md +++ b/dev/ansible/README.md @@ -3,7 +3,7 @@ This is a quick tutorial: * Install ansible: -> apt-get install +> apt-get install ansible * Add ip of server to manage into /etc/ansible/hosts diff --git a/dev/codesniffer/ruleset.xml b/dev/codesniffer/ruleset.xml index 7f16ad02a76..9b5c0931650 100755 --- a/dev/codesniffer/ruleset.xml +++ b/dev/codesniffer/ruleset.xml @@ -350,6 +350,11 @@ + + + 0 + +
'; + $tmp=' jQuery(document).ready(function() { jQuery("#fac_replacement").change(function() { @@ -2160,7 +2160,7 @@ if ($action == 'create') }); }); '; - $text = $langs->trans("InvoiceReplacementAsk") . ' '; + $text = $tmp.$langs->trans("InvoiceReplacementAsk") . ' '; $text .= ''; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1); + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3); print $desc; - print '' . "\n"; + print '
'; } else { - print ''; - print ''; - print ''; - $text = $langs->trans("InvoiceReplacement") . ' '; + print '
'; + $tmp=' '; + $text = $tmp.$langs->trans("InvoiceReplacement") . ' '; $text.= '('.$langs->trans("YouMustCreateInvoiceFromThird").') '; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1); + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3); print $desc; - print '' . "\n"; + print '
'; } if (empty($origin)) @@ -2193,12 +2192,10 @@ if ($action == 'create') if ($socid > 0) { // Credit note - print ''; - print ''; - print ''; + print '
'; + $tmp=' jQuery(document).ready(function() { @@ -2214,7 +2211,7 @@ if ($action == 'create') }); }); '; - $text = $langs->transnoentities("InvoiceAvoirAsk") . ' '; + $text = $tmp.$langs->transnoentities("InvoiceAvoirAsk") . ' '; // $text.=''; $text .= ''; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1); + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); print $desc; print '
'; @@ -2235,22 +2232,22 @@ if ($action == 'create') print '
    0 ? 'checked':'').' /> "; print '
'; - print '' . "\n"; + print '
'; } else { - print ''; - print ''; - print ''; - $text = $langs->trans("InvoiceAvoir") . ' '; + print '
'; + $tmp=' '; + $text = $tmp.$langs->trans("InvoiceAvoir") . ' '; $text.= '('.$langs->trans("YouMustCreateInvoiceFromThird").') '; - $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1); + $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); print $desc; - print '' . "\n"; + print '
' . "\n"; } } - print ''; + print ''; + print ''; if ($socid > 0) @@ -2295,12 +2292,15 @@ if ($action == 'create') print ''; // Project - if (! empty($conf->projet->enabled) && $socid > 0) { - $formproject = new FormProjets($db); + if (! empty($conf->projet->enabled) && $socid > 0) + { + $projectid = GETPOST('projectid')?GETPOST('projectid'):0; + if ($origin == 'project') $projectid = ($originid ? $originid : 0); $langs->load('projects'); print '' . $langs->trans('Project') . ''; - $formproject->select_projects($soc->id, $projectid, 'projectid', 0); + $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0); + print '   id).'">' . $langs->trans("AddProject") . ''; print ''; } @@ -2322,7 +2322,7 @@ if ($action == 'create') print $object->showOptionals($extrafields, 'edit'); } - // Modele PDF + // Template to use by default print '' . $langs->trans('Model') . ''; print ''; include_once DOL_DOCUMENT_ROOT . '/core/modules/facture/modules_facture.php'; @@ -2339,7 +2339,7 @@ if ($action == 'create') { $note_public = $objectsrc->note_public; } - $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); + $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); print $doleditor->Create(1); // Private note @@ -2353,7 +2353,7 @@ if ($action == 'create') { $note_private = $objectsrc->note_private; } - $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, 70); + $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); print $doleditor->Create(1); // print ' print ''; @@ -2420,7 +2420,9 @@ if ($action == 'create') print '' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($objectsrc->total_localtax2) . ""; } print '' . $langs->trans('TotalTTC') . '' . price($objectsrc->total_ttc) . ""; - } else { + } + else + { // Show deprecated optional form to add product line here if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) { print ''; @@ -2479,7 +2481,7 @@ if ($action == 'create') // Button "Create Draft" print '
'; print ''; - print '     '; + print '     '; print ''; print '
'; @@ -3488,50 +3490,50 @@ if ($action == 'create') // Show global modifiers if (! empty($conf->global->INVOICE_US_SITUATION)) { - if ($object->situation_cycle_ref && $object->statut == 0) { - print ''; - print '
'; - print ''; - print ''; - print ''; + if ($object->situation_cycle_ref && $object->statut == 0) { + print ''; + print ''; + print ''; + print ''; + print ''; - if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { - print ' '; - } - print '' . $langs->trans('ModifyAllLines') . ''; - print ' '; - print ' '; - if ($inputalsopricewithtax) print ' '; - print ' '; - print ' '; - print '' . $langs->trans('Progress') . ''; - if (! empty($conf->margin->enabled) && empty($user->societe_id)) - { - print ' '; - if ((! empty($conf->global->DISPLAY_MARGIN_RATES) || ! empty($conf->global->DISPLAY_MARK_RATES)) && $user->rights->margins->liretous) { - print ' '; + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { + print ' '; } - } - print ' '; - print ' '; - print ' '; - print ' '; - print "\n"; + print '' . $langs->trans('ModifyAllLines') . ''; + print ' '; + print ' '; + if ($inputalsopricewithtax) print ' '; + print ' '; + print ' '; + print '' . $langs->trans('Progress') . ''; + if (! empty($conf->margin->enabled) && empty($user->societe_id)) + { + print ' '; + if ((! empty($conf->global->DISPLAY_MARGIN_RATES) || ! empty($conf->global->DISPLAY_MARK_RATES)) && $user->rights->margins->liretous) { + print ' '; + } + } + print ' '; + print ' '; + print ' '; + print ' '; + print "\n"; - if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { - print ' '; + if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { + print ' '; + } + print ''; + print ' '; + print ' '; + print ' '; + print ' '; + print ' '; + print '%'; + print ''; + print ''; + print '
'; } - print ''; - print ' '; - print ' '; - print ' '; - print ' '; - print ' '; - print '%'; - print ''; - print ''; - print ''; - } } // Show object lines @@ -3754,7 +3756,7 @@ if ($action == 'create') } print '
'; - //Select mail models is same action as presend + // Select mail models is same action as presend if (GETPOST('modelselected')) { $action = 'presend'; } @@ -3774,77 +3776,10 @@ if ($action == 'create') $somethingshown = $formfile->numoffiles; // Linked object block - $somethingshown = $object->showLinkedObjectBlock(); + $somethingshown = $form->showLinkedObjectBlock($object); - $linktoelem=''; - - if (! empty($conf->commande->enabled)) - { - $linktoelem.=($linktoelem?'   ':'').'' . $langs->trans('LinkedOrder') . ''; - - print ' - - '; - - print ''; - } - - // Show link to elements + // Show links to link elements + $linktoelem = $form->showLinkToObjectBlock($object,array('order')); if ($linktoelem) print '
'.$linktoelem; // Link for paypal payment @@ -3886,8 +3821,8 @@ if ($action == 'create') $ref = dol_sanitizeFileName($object->ref); include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/')); - $file = $fileparams ['fullname']; + $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); + $file = $fileparams['fullname']; // Define output language $outputlangs = $langs; @@ -3911,14 +3846,16 @@ if ($action == 'create') dol_print_error($db, $result); exit(); } - $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/')); - $file = $fileparams ['fullname']; + $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/').'[^\-]+'); + $file = $fileparams['fullname']; } print '
'; print_titre($langs->trans($titreform)); // Cree l'objet formulaire mail + dol_fiche_head(); + include_once DOL_DOCUMENT_ROOT . '/core/class/html.formmail.class.php'; $formmail = new FormMail($db); $formmail->param['langsmodels']=(empty($newlang)?$langs->defaultlang:$newlang); @@ -3990,7 +3927,7 @@ if ($action == 'create') print $formmail->get_form(); - print '
'; + dol_fiche_end(); } } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index a347ccdbca8..fc3d8936edf 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -92,18 +92,16 @@ class Facture extends CommonInvoice var $revenuestamp; /** * @deprecated + * @see note_private, note_public */ var $note; var $note_private; var $note_public; /** - * Check constants for more info: - * - STATUS_DRAFT - * - STATUS_VALIDATED - * - STATUS_PAID - * - STATUS_ABANDONED + * Invoice status * @var int + * @see Facture::STATUS_DRAFT, Facture::STATUS_VALIDATED, Facture::STATUS_PAID, Facture::STATUS_ABANDONED */ var $statut; //! Fermeture apres paiement partiel: discount_vat, badcustomer, abandon @@ -131,6 +129,9 @@ class Facture extends CommonInvoice * @deprecated */ var $products=array(); + /** + * @var FactureLigne[] + */ var $lines=array(); var $line; var $extraparams=array(); @@ -1119,7 +1120,8 @@ class Facture extends CommonInvoice $objp = $this->db->fetch_object($result); $line = new FactureLigne($this->db); - $line->rowid = $objp->rowid; + $line->id = $objp->rowid; + $line->rowid = $objp->rowid; // deprecated $line->label = $objp->custom_label; // deprecated $line->desc = $objp->description; // Description line $line->product_type = $objp->product_type; // Type of line @@ -2105,6 +2107,11 @@ class Facture extends CommonInvoice */ function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits=0, $fk_remise_except='', $price_base_type='HT', $pu_ttc=0, $type=self::TYPE_STANDARD, $rang=-1, $special_code=0, $origin='', $origin_id=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_options=0, $situation_percent=100, $fk_prev_id='', $fk_unit = null) { + // Deprecation warning + if ($label) { + dol_syslog(__METHOD__ . ": using line label is deprecated", LOG_WARNING); + } + global $mysoc, $conf, $langs; dol_syslog(get_class($this)."::addline facid=$this->id,desc=$desc,pu_ht=$pu_ht,qty=$qty,txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, fk_product=$fk_product,remise_percent=$remise_percent,date_start=$date_start,date_end=$date_end,ventil=$ventil,info_bits=$info_bits,fk_remise_except=$fk_remise_except,price_base_type=$price_base_type,pu_ttc=$pu_ttc,type=$type, fk_unit=$fk_unit", LOG_DEBUG); @@ -2289,6 +2296,11 @@ class Facture extends CommonInvoice */ function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type= self::TYPE_STANDARD, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $situation_percent=0, $fk_unit = null) { + // Deprecation warning + if ($label) { + dol_syslog(__METHOD__ . ": using line label is deprecated", LOG_WARNING); + } + include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; global $mysoc; @@ -3203,7 +3215,7 @@ class Facture extends CommonInvoice $response = new WorkboardResponse(); $response->warning_delay=$conf->facture->client->warning_delay/60/60/24; $response->label=$langs->trans("CustomerBillsUnpaid"); - $response->url=DOL_URL_ROOT.'/compta/facture/impayees.php'; + $response->url=DOL_URL_ROOT.'/compta/facture/list.php?search_status=1'; $response->img=img_object($langs->trans("Bills"),"bill"); while ($obj=$this->db->fetch_object($resql)) @@ -3685,7 +3697,10 @@ class FactureLigne extends CommonInvoiceLine var $fk_facture; //! Id parent line var $fk_parent_line; - var $label; // deprecated + /** + * @deprecated + */ + var $label; //! Description ligne var $desc; @@ -3717,8 +3732,16 @@ class FactureLigne extends CommonInvoiceLine //var $remise; // Montant calcule de la remise % sur PU HT (exemple 20) // From llx_product + /** + * @deprecated + * @see product_ref + */ var $ref; // Product ref (deprecated) var $product_ref; // Product ref + /** + * @deprecated + * @see product_label + */ var $libelle; // Product label (deprecated) var $product_label; // Product label var $product_desc; // Description produit diff --git a/htdocs/compta/facture/class/facturestats.class.php b/htdocs/compta/facture/class/facturestats.class.php index 4028849b5fa..5d8d22cfa9d 100644 --- a/htdocs/compta/facture/class/facturestats.class.php +++ b/htdocs/compta/facture/class/facturestats.class.php @@ -84,6 +84,8 @@ class FactureStats extends Stats $this->where.=" AND f.fk_soc = ".$this->socid; } if ($this->userid > 0) $this->where.=' AND f.fk_user_author = '.$this->userid; + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $this->where.= " AND f.type IN (0,1,2)"; + else $this->where.= " AND f.type IN (0,1,2,3)"; } @@ -206,7 +208,7 @@ class FactureStats extends Stats $sql = "SELECT product.ref, COUNT(product.ref) as nb, SUM(tl.".$this->field_line.") as total, AVG(tl.".$this->field_line.") as avg"; $sql.= " FROM ".$this->from.", ".$this->from_line.", ".MAIN_DB_PREFIX."product as product"; - //if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + if (!$user->rights->societe->client->voir && !$this->socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE ".$this->where; $sql.= " AND f.rowid = tl.fk_facture AND tl.fk_product = product.rowid"; $sql.= " AND f.datef BETWEEN '".$this->db->idate(dol_get_first_day($year,1,false))."' AND '".$this->db->idate(dol_get_last_day($year,12,false))."'"; diff --git a/htdocs/compta/facture/document.php b/htdocs/compta/facture/document.php index 60c47564743..e4f9846309a 100644 --- a/htdocs/compta/facture/document.php +++ b/htdocs/compta/facture/document.php @@ -37,6 +37,7 @@ $langs->load('propal'); $langs->load('compta'); $langs->load('other'); $langs->load("bills"); +$langs->load('companies'); $id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 6c82dcd4d8a..2668f0f1af6 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -2,10 +2,11 @@ /* Copyright (C) 2002-2003 Rodolphe Quiedeville * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2013 Florian Henry - * Copyright (C) 2013 Juanjo Menent + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2013 Juanjo Menent * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2012 Cedric Salvador + * Copyright (C) 2015 Alexandre Spangaro * * 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 @@ -128,6 +129,8 @@ if ($action == 'create') print ''; print ''; print ''; + + dol_fiche_head(); $rowspan=4; if (! empty($conf->projet->enabled) && $object->fk_project > 0) $rowspan++; @@ -139,7 +142,7 @@ if ($action == 'create') // Third party print ''.$langs->trans("Customer").''.$object->client->getNomUrl(1,'customer').''; print ''; - //print $langs->trans("NotePrivate"); + print $langs->trans("Comment"); print ''; // Title @@ -371,10 +374,15 @@ if ($action == 'create') print ''; print ''; } - print '
'; - print "\n"; print "\n"; + dol_fiche_end(); + + print '
'; + print '     '; + print ''; + print '
'; + print "\n"; } else { @@ -432,7 +440,7 @@ else $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id,'none'); print ""; - print ''.$langs->trans("Note").''.nl2br($object->note_private).""; + print ''.$langs->trans("Comment").''.nl2br($object->note_private).""; print ""; diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 08a14b75602..6d9a6329d4e 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -10,6 +10,7 @@ * Copyright (C) 2013 Florian Henry * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2015 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 @@ -88,6 +89,9 @@ $search_sale = GETPOST('search_sale','int'); $day = GETPOST('day','int'); $month = GETPOST('month','int'); $year = GETPOST('year','int'); +$day_lim = GETPOST('day_lim','int'); +$month_lim = GETPOST('month_lim','int'); +$year_lim = GETPOST('year_lim','int'); $filtre = GETPOST('filtre'); // Security check @@ -213,6 +217,19 @@ else if ($year > 0) { $sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'"; } +if ($month_lim > 0) +{ + if ($year_lim > 0 && empty($day_lim)) + $sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_get_first_day($year_lim,$month_lim,false))."' AND '".$db->idate(dol_get_last_day($year_lim,$month_lim,false))."'"; + else if ($year_lim > 0 && ! empty($day_lim)) + $sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_lim, $day_lim, $year_lim))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_lim, $day_lim, $year_lim))."'"; + else + $sql.= " AND date_format(f.date_lim_reglement, '%m') = '".$month_lim."'"; +} +else if ($year_lim > 0) +{ + $sql.= " AND f.date_lim_reglement BETWEEN '".$db->idate(dol_get_first_day($year_lim,1,false))."' AND '".$db->idate(dol_get_last_day($year_lim,12,false))."'"; +} if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale; if ($search_user > 0) { @@ -322,7 +339,11 @@ if ($resql) print ''; $formother->select_year($year?$year:-1,'year',1, 20, 5); print ''; - print ' '; + print ''; + if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; + print ''; + $formother->select_year($year_lim?$year_lim:-1,'year_lim',1, 20, 5); + print ''; print ''; print ''; print ' '; diff --git a/htdocs/compta/facture/mergepdftool.php b/htdocs/compta/facture/mergepdftool.php index ff1bde24466..146ee53736c 100644 --- a/htdocs/compta/facture/mergepdftool.php +++ b/htdocs/compta/facture/mergepdftool.php @@ -275,7 +275,7 @@ if ($action == "builddoc" && $user->rights->facture->lire && ! GETPOST('button_s { $arrayofinclusion=array(); foreach($_POST['toGenerate'] as $tmppdf) $arrayofinclusion[]=preg_quote($tmppdf.'.pdf','/'); - $factures = dol_dir_list($conf->facture->dir_output,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC); + $factures = dol_dir_list($conf->facture->dir_output,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true); // liste les fichiers $files = array(); @@ -284,7 +284,7 @@ if ($action == "builddoc" && $user->rights->facture->lire && ! GETPOST('button_s { foreach($factures as $facture) { - if(strstr($facture["name"],$basename)) + if (strstr($facture["name"],$basename)) { $files[] = $conf->facture->dir_output.'/'.$basename.'/'.$facture["name"]; } diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index 6954ad46249..0e1763d4b86 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -36,6 +36,7 @@ if (!$user->rights->facture->lire) accessforbidden(); $langs->load("bills"); $langs->load("banks"); $langs->load("withdrawals"); +$langs->load('companies'); $id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int')); // For backward compatibility $ref=GETPOST('ref','alpha'); @@ -396,7 +397,7 @@ if ($object->id > 0) } print ""; print ''; - + // Montants print ''.$langs->trans('AmountHT').''; print ''.price($object->total_ht).''; diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index 3d3a8ab2197..11296bda93e 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -775,7 +775,7 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire) $i = 0; print ''; - print ''; + print ''; if (! empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) print ''; print ''; print ''; diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 58865c38540..98fe402266c 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -6,7 +6,7 @@ * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2012 Cédric Salvador * Copyright (C) 2014 Raphaël Doursenaud - * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> + * Copyright (C) 2014 Teddy Andreotti <125155@supinfo.com> * * 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 @@ -403,6 +403,8 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; print ''; + dol_fiche_head(); + print '
'.$langs->trans("BillsCustomersUnpaid",$num).' '.$num.'
'.$langs->trans("BillsCustomersUnpaid",$num).' '.$num.''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("Received").'
'; // Third party @@ -462,6 +464,8 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print '
'; + dol_fiche_end(); + /* * List of unpaid invoices */ diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 077bbde2420..60d669fcacf 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -40,7 +40,16 @@ class Paiement extends CommonObject var $ref; var $facid; var $datepaye; - var $total; // deprecated + /** + * @deprecated + * @see amount, amounts + */ + var $total; + /** + * @deprecated + * @see amount, amounts + */ + var $montant; var $amount; // Total amount of payment var $amounts=array(); // Array of amounts var $author; diff --git a/htdocs/compta/salaries/document.php b/htdocs/compta/salaries/document.php new file mode 100644 index 00000000000..71f10388ace --- /dev/null +++ b/htdocs/compta/salaries/document.php @@ -0,0 +1,136 @@ + + * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005 Simon TOSSER + * Copyright (C) 2011-2012 Juanjo Menent + * Copyright (C) 2013 Cédric Salvador + * Copyright (C) 2015 Alexandre Spangaro + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/compta/salaries/document.php + * \ingroup salaries + * \brief Page of linked files onto salaries + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/salaries.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/salaries/class/paymentsalary.class.php'; + +$langs->load("other"); +$langs->load("salaries"); +$langs->load("companies"); + +$id = GETPOST('id','int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action','alpha'); +$confirm = GETPOST('confirm','alpha'); + +// Security check +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'salaries', $id, ''); + + +// Get parameters +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if ($page == -1) { $page = 0; } +$offset = $conf->liste_limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (! $sortorder) $sortorder="ASC"; +if (! $sortfield) $sortfield="name"; + + +$object = new PaymentSalary($db); +$object->fetch($id, $ref); + +$upload_dir = $conf->salaries->dir_output.'/'.dol_sanitizeFileName($object->id); +$modulepart='salaries'; + + +/* + * Actions + */ + +include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; + + +/* + * View + */ + +$form = new Form($db); + +llxHeader("","",$langs->trans("SalaryPayment")); + + +if ($object->id) +{ + $object->fetch_thirdparty(); + + $head=salaries_prepare_head($object); + + dol_fiche_head($head, 'documents', $langs->trans("SalaryPayment"), 0, 'payment'); + + + // Construit liste des fichiers + $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); + $totalsize=0; + foreach($filearray as $key => $file) + { + $totalsize+=$file['size']; + } + + + print ''; + + $linkback = ''.$langs->trans("BackToList").''; + + // Ref + print ''; + + // Societe + //print ""; + + print ''; + print ''; + print '
'.$langs->trans("Ref").''; + print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', ''); + print '
".$langs->trans("Company")."".$object->client->getNomUrl(1)."
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
'; + + print ''; + + $modulepart = 'salaries'; + $permission = $user->rights->salaries->write; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; + +} +else +{ + print $langs->trans("ErrorUnknown"); +} + +llxFooter(); + +$db->close(); diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index 740f6f3bf5e..4d638e23cf7 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -501,7 +501,7 @@ if ($id > 0) } // Emettre paiement - if ($object->paye == 0 && ((price2num($object->amount) < 0 && round($resteapayer) < 0) || (price2num($object->amount) > 0 && round($resteapayer) > 0)) && $user->rights->tax->charges->creer) + if ($object->paye == 0 && ((price2num($object->amount) < 0 && price2num($resteapayer, 'MT') < 0) || (price2num($object->amount) > 0 && price2num($resteapayer, 'MT') > 0)) && $user->rights->tax->charges->creer) { print "id&action=create\">".$langs->trans("DoPayment").""; } diff --git a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php index d58e0add8ab..45b2c51acfa 100644 --- a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php +++ b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php @@ -40,6 +40,11 @@ class PaymentSocialContribution extends CommonObject var $datec=''; var $tms=''; var $datep=''; + /** + * @deprecated + * @see amount + */ + var $total; var $amount; // Total amount of payment var $amounts=array(); // Array of amounts var $fk_typepaiement; diff --git a/htdocs/contact/canvas/actions_contactcard_common.class.php b/htdocs/contact/canvas/actions_contactcard_common.class.php index 9e6624dda72..ad628fd6574 100644 --- a/htdocs/contact/canvas/actions_contactcard_common.class.php +++ b/htdocs/contact/canvas/actions_contactcard_common.class.php @@ -51,6 +51,8 @@ abstract class ActionsContactCardCommon */ private function getInstanceDao() { + dol_syslog(__METHOD__ . " is deprecated", LOG_WARNING); + if (! is_object($this->object)) { $modelclassfile = dol_buildpath('/'.$this->dirmodule.'/canvas/'.$this->canvas.'/dao_'.$this->targetmodule.'_'.$this->canvas.'.class.php'); diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 3d75c4a2036..e39c5502b4d 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -40,6 +40,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT. '/core/class/html.form.class.php'; require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; +require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; $langs->load("companies"); $langs->load("users"); $langs->load("other"); @@ -201,7 +202,11 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); - if ($ret < 0) $error++; + if ($ret < 0) + { + $error++; + $action = 'create'; + } if (! GETPOST("lastname")) { @@ -216,7 +221,17 @@ if (empty($reshook)) { $error++; $errors=array_merge($errors,($object->error?array($object->error):$object->errors)); $action = 'create'; - } + } else { + // Categories association + $contcats = GETPOST( 'contcats', 'array' ); + if (!empty( $contcats )) { + $cat = new Categorie( $db ); + foreach ($contcats as $id_category) { + $cat->fetch( $id_category ); + $cat->add_type( $object, 'contact' ); + } + } + } } if (! $error && $id > 0) @@ -309,8 +324,22 @@ if (empty($reshook)) $result = $object->update($contactid, $user); - if ($result > 0) - { + if ($result > 0) { + // Categories association + // First we delete all categories association + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'categorie_contact'; + $sql .= ' WHERE fk_socpeople = ' . $object->id; + $db->query( $sql ); + + // Then we add the associated categories + $categories = GETPOST( 'contcats', 'array' ); + if (!empty( $categories )) { + $cat = new Categorie( $db ); + foreach ($categories as $id_category) { + $cat->fetch( $id_category ); + $cat->add_type( $object, 'contact' ); + } + } $object->old_lastname=''; $object->old_firstname=''; $action = 'view'; @@ -576,6 +605,15 @@ else print $form->selectarray('priv',$selectarray,(GETPOST("priv",'alpha')?GETPOST("priv",'alpha'):$object->priv),0); print ''; + // Categories + if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) { + print '' . fieldLabel( 'Categories', 'contcats' ) . ''; + $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, 'parent', null, null, 1 ); + print $form->multiselectarray( 'contcats', $cate_arbo, GETPOST( 'contcats', 'array' ), null, null, null, + null, '90%' ); + print ""; + } + // Other attributes $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook @@ -815,6 +853,20 @@ else print $object->getLibStatut(4); print ''; + // Categories + if (!empty( $conf->categorie->enabled ) && !empty( $user->rights->categorie->lire )) { + print '' . fieldLabel( 'Categories', 'contcats' ) . ''; + print ''; + $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, null, null, null, 1 ); + $c = new Categorie( $db ); + $cats = $c->containing( $object->id, Categorie::TYPE_CONTACT ); + foreach ($cats as $cat) { + $arrayselected[] = $cat->id; + } + print $form->multiselectarray( 'contcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%' ); + print ""; + } + // Other attributes $parameters=array('colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook @@ -1039,6 +1091,15 @@ else print $object->getLibStatut(4); print ''; print ''."\n"; + + // Categories + if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) { + print '' . $langs->trans( "Categories" ) . ''; + print ''; + print $form->showCategories( $object->id, 'contact', 1 ); + print ''; + } + // Other attributes $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook @@ -1101,18 +1162,14 @@ else { if ($user->rights->societe->contact->creer) { - print ''.$langs->trans('Modify').''; + print ''.$langs->trans('Modify').''; } if (! $object->user_id && $user->rights->user->user->creer) { - print ''.$langs->trans("CreateDolibarrLogin").''; + print ''.$langs->trans("CreateDolibarrLogin").''; } - if ($user->rights->societe->contact->supprimer) - { - print ''.$langs->trans('Delete').''; - } // Activer if ($object->statut == 0 && $user->rights->societe->contact->creer) { @@ -1122,6 +1179,12 @@ else if ($object->statut == 1 && $user->rights->societe->contact->creer) { print ''.$langs->trans("DisableUser").''; + } + + // Delete + if ($user->rights->societe->contact->supprimer) + { + print ''.$langs->trans('Delete').''; } } diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 72590c82e82..0e3c4b0a2bc 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -50,9 +50,21 @@ class Contact extends CommonObject var $zip; var $town; - var $fk_departement; // deprecated - var $departement_code; // deprecated - var $departement; // deprecated + /** + * @deprecated + * @see state_id + */ + var $fk_departement; + /** + * @deprecated + * @see state_code + */ + var $departement_code; + /** + * @deprecated + * @see state + */ + var $departement; var $state_id; // Id of department var $state_code; // Code of department var $state; // Label of department @@ -80,7 +92,11 @@ class Contact extends CommonObject var $birthday; var $default_lang; var $note_public; // Public note - var $note; // deprecated + /** + * @deprecated + * @see note_public, note_private + */ + var $note; var $note_private; // Private note var $no_email; // 1=Don't send e-mail to this contact, 0=do @@ -629,6 +645,13 @@ class Contact extends CommonObject } } + // Retreive all extrafield for contact + // fetch optionals attributes and labels + require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); + $extrafields=new ExtraFields($this->db); + $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); + $this->fetch_optionals($this->id,$extralabels); + return 1; } else @@ -1101,4 +1124,4 @@ class Contact extends CommonObject return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables); } -} \ No newline at end of file +} diff --git a/htdocs/contact/document.php b/htdocs/contact/document.php index 2241a1e67f1..9a5ab3b0f07 100644 --- a/htdocs/contact/document.php +++ b/htdocs/contact/document.php @@ -80,8 +80,9 @@ llxHeader("",$langs->trans("Contact"), $helpurl); if ($object->id) { $head = contact_prepare_head($object); + $title = (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses")); - dol_fiche_head($head, 'documents', $langs->trans("Contact"), 0, 'contact'); + dol_fiche_head($head, 'documents', $title, 0, 'contact'); // Construit liste des fichiers diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 72eee453c9f..11d46ad3fc4 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -159,7 +159,7 @@ else if ($search_priv == '1') $sql .= " AND (p.priv='1' AND p.fk_user_creat=".$user->id.")"; } -if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$search_categ; +if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$db->escape($search_categ); if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL"; if ($search_firstlast_only) { @@ -256,11 +256,11 @@ if ($result) { $contactstatic=new Contact($db); - $param ='&begin='.urlencode($begin).'&view='.urlencode($view).'&userid='.urlencode($userid).'&contactname='.urlencode($sall); - $param.='&type='.urlencode($type).'&view='.urlencode($view).'&search_lastname='.urlencode($search_lastname).'&search_firstname='.urlencode($search_firstname).'&search_societe='.urlencode($search_societe).'&search_email='.urlencode($search_email); - if (!empty($search_categ)) $param.='&search_categ='.$search_categ; - if ($search_status != '') $param.='&search_status='.$search_status; - if ($search_priv == '0' || $search_priv == '1') $param.="&search_priv=".urlencode($search_priv); + $param ='&begin='.htmlspecialchars($begin).'&view='.htmlspecialchars($view).'&userid='.htmlspecialchars($userid).'&contactname='.htmlspecialchars($sall); + $param.='&type='.htmlspecialchars($type).'&view='.htmlspecialchars($view).'&search_lastname='.htmlspecialchars($search_lastname).'&search_firstname='.htmlspecialchars($search_firstname).'&search_societe='.htmlspecialchars($search_societe).'&search_email='.htmlspecialchars($search_email); + if (!empty($search_categ)) $param.='&search_categ='.htmlspecialchars($search_categ); + if ($search_status != '') $param.='&search_status='.htmlspecialchars($search_status); + if ($search_priv == '0' || $search_priv == '1') $param.="&search_priv=".htmlspecialchars($search_priv); $num = $db->num_rows($result); $i = 0; @@ -269,7 +269,7 @@ if ($result) print '
'; print ''; - print ''; + print ''; print ''; print ''; @@ -317,36 +317,36 @@ if ($result) // Ligne des champs de filtres print ''; print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) { print ''; - print ''; + print ''; print ''; } print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; if (! empty($conf->skype->enabled)) { print ''; - print ''; + print ''; print ''; } print ' '; diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index dd48b27684f..6bf7dcaeacc 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -823,10 +823,8 @@ else if ($action == 'remove_file' && $user->rights->contrat->creer) { $upload_dir = $conf->contrat->dir_output; $file = $upload_dir . '/' . GETPOST('file'); $ret = dol_delete_file($file, 0, 0, 0, $object); - if ($ret) - setEventMessage($langs->trans("FileWasRemoved", GETPOST('file'))); - else - setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), 'errors'); + if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('file'))); + else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('file')), 'errors'); } } @@ -1873,10 +1871,13 @@ else $somethingshown = $formfile->show_documents('contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang); - /* - * Linked object block - */ - $somethingshown=$object->showLinkedObjectBlock(); + // Linked object block + $somethingshown = $form->showLinkedObjectBlock($object); + + // Show links to link elements + $linktoelem = $form->showLinkToObjectBlock($object); + if ($linktoelem) print '
'.$linktoelem; + print '
'; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 08bc8387387..fb0038b509f 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -154,6 +154,7 @@ class Contrat extends CommonObject /** * @deprecated Use fk_project instead + * @see fk_project */ var $fk_projet; @@ -1642,6 +1643,8 @@ class Contrat extends CommonObject */ function update_statut($user) { + dol_syslog(__METHOD__ . " is deprecated", LOG_WARNING); + // If draft, we keep it (should not happen) if ($this->statut == 0) return 1; @@ -2165,6 +2168,7 @@ class ContratLigne extends CommonObjectLine /** * @var string * @deprecated Use $label instead + * @see label */ public $libelle; @@ -2189,6 +2193,7 @@ class ContratLigne extends CommonObjectLine /** * @var float * @deprecated Use $price_ht instead + * @see price_ht */ public $price; diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 25b5d80fa98..669f2b09775 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -100,7 +100,8 @@ $sql.= ", ".MAIN_DB_PREFIX."contrat as c"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat"; $sql.= " WHERE c.fk_soc = s.rowid "; $sql.= " AND c.entity = ".$conf->entity; -if ($socid) $sql.= " AND s.rowid = ".$socid; +if ($socid) $sql.= " AND s.rowid = ".$db->escape($socid); +if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($search_name) { $sql .= natural_search('s.nom', $search_name); @@ -112,7 +113,7 @@ if (!empty($search_ref_supplier)) { $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier); } -if ($search_sale > 0) +if ($search_sale > 0) { $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale; } @@ -131,7 +132,7 @@ if ($resql) $i = 0; print_barre_liste($langs->trans("ListOfContracts"), $page, $_SERVER["PHP_SELF"], '&search_contract='.$search_contract.'&search_name='.$search_name, $sortfield, $sortorder,'',$num,$totalnboflines,'title_commercial.png'); - + print ''; print ''; @@ -144,7 +145,7 @@ if ($resql) $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user); $moreforfilter.='       '; } - + if ($moreforfilter) { print ''; @@ -152,13 +153,14 @@ if ($resql) print $moreforfilter; print ''; } - + print ''; - $param='&search_contract='.$search_contract; - $param.='&search_name='.$search_name; - $param.='&search_ref_supplier='.$search_ref_supplier; + + $param='&search_contract='.$search_contract; + $param.='&search_name='.$search_name; + $param.='&search_ref_supplier='.$search_ref_supplier; $param.='&search_sale=' .$search_sale; - + print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "c.rowid","","$param",'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("RefCustomer"), $_SERVER["PHP_SELF"], "c.ref_supplier","","$param",'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Company"), $_SERVER["PHP_SELF"], "s.nom","","$param",'',$sortfield,$sortorder); @@ -175,13 +177,13 @@ if ($resql) print ''; print ''; print ''; print ''; print ''; print ''; //print ''; @@ -202,7 +204,7 @@ if ($resql) print ''; print ''; //print ''; - + // Sales Rapresentatives print ''; - - + + print ''; //print ''; print ''; diff --git a/htdocs/core/actions_extrafields.inc.php b/htdocs/core/actions_extrafields.inc.php index 03d724b9bba..4c5f0b512d2 100644 --- a/htdocs/core/actions_extrafields.inc.php +++ b/htdocs/core/actions_extrafields.inc.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2015 Laurent Destailleur * * 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 @@ -148,7 +148,21 @@ if ($action == 'add') } } - $result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$default_value,$params,(GETPOST('alwayseditable')?1:0)); + $result=$extrafields->addExtraField( + GETPOST('attrname'), + GETPOST('label'), + GETPOST('type'), + GETPOST('pos'), + $extrasize, + $elementtype, + (GETPOST('unique')?1:0), + (GETPOST('required')?1:0), + $default_value, + $params, + (GETPOST('alwayseditable')?1:0), + (GETPOST('perms')?GETPOST('perms'):''), + (GETPOST('list')?1:0) + ); if ($result > 0) { setEventMessage($langs->trans('SetupSaved')); @@ -285,7 +299,20 @@ if ($action == 'update') $params['options'][$key] = $value; } } - $result=$extrafields->update($_POST['attrname'],$_POST['label'],$_POST['type'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$pos,$params,(GETPOST('alwayseditable')?1:0)); + $result=$extrafields->update( + GETPOST('attrname'), + GETPOST('label'), + GETPOST('type'), + $extrasize, + $elementtype, + (GETPOST('unique')?1:0), + (GETPOST('required')?1:0), + $pos, + $params, + (GETPOST('alwayseditable')?1:0), + (GETPOST('perms')?GETPOST('perms'):''), + (GETPOST('list')?1:0) + ); if ($result > 0) { setEventMessage($langs->trans('SetupSaved')); diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 6e41384dbce..1aadc47b79e 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -37,7 +37,7 @@ class CMailFile { var $subject; // Topic: Subject of email - var $addr_from; // From: Label and EMail of sender (must include '<>'). For example '' or 'John Doe ' or '') + var $addr_from; // From: Label and EMail of sender (must include '<>'). For example '' or 'John Doe ' or '') // Sender: Who send the email ("Sender" has sent emails on behalf of "From"). // Use it when the "From" is an email of a domain that is a SPF protected domain, and sending smtp server is not this domain. In such case, use for Sender an email of the protected domain. // Return-Path: Email where to send bounds. @@ -387,7 +387,7 @@ class CMailFile // If Windows, sendmail_from must be defined if (isset($_SERVER["WINDIR"])) { - if (empty($this->addr_from)) $this->addr_from = 'robot@mydomain.com'; + if (empty($this->addr_from)) $this->addr_from = 'robot@example.com'; @ini_set('sendmail_from',$this->getValidAddress($this->addr_from,2)); } diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index d31137ac1cf..1d5858fa746 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -119,6 +119,7 @@ abstract class CommonDocGenerator 'mycompany_idprof5'=>$mysoc->idprof5, 'mycompany_idprof6'=>$mysoc->idprof6, 'mycompany_vatnumber'=>$mysoc->tva_intra, + 'mycompany_object'=>$mysoc->object, // Only private not exists for "mysoc" 'mycompany_note_private'=>$mysoc->note_private, diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 0bd0625ee5d..8ae7332fc6e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -7,7 +7,7 @@ * Copyright (C) 2012-2013 Christophe Battarel * Copyright (C) 2011-2014 Philippe Grand * Copyright (C) 2012-2015 Marcos García - * Copyright (C) 2012-2014 Raphaël Doursenaud + * Copyright (C) 2012-2015 Raphaël Doursenaud * Copyright (C) 2012 Cedric Salvador * * This program is free software; you can redistribute it and/or modify @@ -44,6 +44,7 @@ abstract class CommonObject /** * @var string Error string * @deprecated Use instead the array of error strings + * @see errors */ public $error; @@ -82,7 +83,7 @@ abstract class CommonObject public $errors=array(); /** - * @var string Can be used to pass information when only object is provided to method + * @var string[] Can be used to pass information when only object is provided to method */ public $context=array(); @@ -96,7 +97,24 @@ abstract class CommonObject public $lastname; public $firstname; public $civility_id; + /** + * @deprecated + * @see thirdparty + */ + public $client; + /** + * @var Societe + */ public $thirdparty; + /** + * @deprecated + * @see project + */ + public $projet; + /** + * @var Project + */ + public $project; // No constructor as it is an abstract class @@ -113,13 +131,15 @@ abstract class CommonObject */ static function isExistingObject($element, $id, $ref='', $ref_ext='') { - global $db; + global $db,$conf; $sql = "SELECT rowid, ref, ref_ext"; $sql.= " FROM ".MAIN_DB_PREFIX.$element; - if ($id > 0) $sql.= " WHERE rowid = ".$db->escape($id); - else if ($ref) $sql.= " WHERE ref = '".$db->escape($ref)."'"; - else if ($ref_ext) $sql.= " WHERE ref_ext = '".$db->escape($ref_ext)."'"; + $sql.= " WHERE entity IN (".getEntity($element).")" ; + + if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); + else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; + else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; else { $error='ErrorWrongParameters'; dol_print_error(get_class()."::isExistingObject ".$error, LOG_ERR); @@ -525,9 +545,9 @@ abstract class CommonObject * Return array with list of possible values for type of contacts * * @param string $source 'internal', 'external' or 'all' - * @param string $order Sort order by : 'code' or 'rowid' - * @param string $option 0=Return array id->label, 1=Return array code->label - * @param string $activeonly 0=all status of contact, 1=only the active + * @param string $order Sort order by 'code' or 'rowid' + * @param int $option 0=Return array id->label, 1=Return array code->label + * @param int $activeonly 0=all status of contact, 1=only the active * @param string $code Type of contact (Example: 'CUSTOMER', 'SERVICE') * @return array Array list of type of contacts (id->label if option=0, code->label if option=1) */ @@ -541,7 +561,7 @@ abstract class CommonObject $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle"; $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; $sql.= " WHERE tc.element='".$this->element."'"; - if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active type + if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types if (! empty($source) && $source != 'all') $sql.= " AND tc.source='".$source."'"; if (! empty($code)) $sql.= " AND tc.code='".$code."'"; $sql.= " ORDER by tc.".$order; @@ -626,12 +646,12 @@ abstract class CommonObject } /** - * Charge le contact d'id $id dans this->contact + * Load object contact with id=$this->contactid into $this->contact * * @param int $contactid Id du contact. Use this->contactid if empty. * @return int <0 if KO, >0 if OK */ - function fetch_contact($contactid='') + function fetch_contact($contactid=null) { if (empty($contactid)) $contactid=$this->contactid; @@ -759,10 +779,14 @@ abstract class CommonObject */ function fetch_projet() { + include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + + if (empty($this->fk_project) && ! empty($this->fk_projet)) $this->fk_project = $this->fk_projet; // For backward compatibility if (empty($this->fk_project)) return 0; $project = new Project($this->db); $result = $project->fetch($this->fk_project); + $this->projet = $project; // deprecated $this->project = $project; return $result; @@ -858,14 +882,14 @@ abstract class CommonObject /** * Update a specific field into database * - * @param string $field Field to update - * @param mixed $value New value - * @param string $table To force other table element or element line (should not be used) - * @param int $id To force other object id (should not be used) - * @param string $format Data format ('text', 'date'). 'text' is used if not defined - * @param string $id_field To force rowid field name. 'rowid' is used it not defined - * @param string $user Update last update fields also if user object provided - * @return int <0 if KO, >0 if OK + * @param string $field Field to update + * @param mixed $value New value + * @param string $table To force other table element or element line (should not be used) + * @param int $id To force other object id (should not be used) + * @param string $format Data format ('text', 'date'). 'text' is used if not defined + * @param string $id_field To force rowid field name. 'rowid' is used it not defined + * @param User|string $user Update last update fields also if user object provided + * @return int <0 if KO, >0 if OK */ function setValueFrom($field, $value, $table='', $id='', $format='', $id_field='', $user='') { @@ -1639,9 +1663,10 @@ abstract class CommonObject /** * Update public note (kept for backward compatibility) * - * @param string $note New value for note - * @return int <0 if KO, >0 if OK - * @deprecated + * @param string $note New value for note + * @return int <0 if KO, >0 if OK + * @deprecated + * @see update_note() */ function update_note_public($note) { @@ -1655,10 +1680,10 @@ abstract class CommonObject * @param int $exclspec >0 = Exclude special product (product_type=9) * @param string $roundingadjust 'none'=Do nothing, 'auto'=Use default method (MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND if defined, or '0'), '0'=Force use total of rounding, '1'=Force use rounding of total * @param int $nodatabaseupdate 1=Do not update database. Update only properties of object. - * @param Societe $seller If roundingadjust is '0' or '1', it means we recalculate total for lines before calculating total for object. For this, we need seller object. + * @param Societe $seller If roundingadjust is '0' or '1', it means we recalculate total for lines before calculating total for object and for this, we need seller object. * @return int <0 if KO, >0 if OK */ - function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller='') + function update_price($exclspec=0,$roundingadjust='none',$nodatabaseupdate=0,$seller=null) { global $conf; @@ -2555,88 +2580,19 @@ abstract class CommonObject // TODO: All functions here must be redesigned and moved as they are not business functions but output functions // -------------------- - /* This is to show linked object block */ - /** - * Show linked object block - * TODO Move this into html.class.php - * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. + * Show linked object block. * - * @return int + * @return int <0 if KO, >0 if OK + * @deprecated 3.8 Use instead $form->shoLinkedObjectBlock($object) */ function showLinkedObjectBlock() { - global $conf,$langs,$hookmanager; - global $bc; - - $this->fetchObjectLinked(); - - // Bypass the default method - $hookmanager->initHooks(array('commonobject')); - $parameters=array(); - $reshook=$hookmanager->executeHooks('showLinkedObjectBlock',$parameters,$this,$action); // Note that $action and $object may have been modified by hook - - if (empty($reshook)) - { - $num = count($this->linkedObjects); - - foreach($this->linkedObjects as $objecttype => $objects) - { - $tplpath = $element = $subelement = $objecttype; - - if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) - { - $element = $regs[1]; - $subelement = $regs[2]; - $tplpath = $element.'/'.$subelement; - } - - // To work with non standard path - if ($objecttype == 'facture') { - $tplpath = 'compta/'.$element; - if (empty($conf->facture->enabled)) continue; // Do not show if module disabled - } - else if ($objecttype == 'propal') { - $tplpath = 'comm/'.$element; - if (empty($conf->propal->enabled)) continue; // Do not show if module disabled - } - else if ($objecttype == 'askpricesupplier') { - $tplpath = 'comm/'.$element; - if (empty($conf->askpricesupplier->enabled)) continue; // Do not show if module disabled - } - else if ($objecttype == 'shipping' || $objecttype == 'shipment') { - $tplpath = 'expedition'; - if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled - } - else if ($objecttype == 'delivery') { - $tplpath = 'livraison'; - if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled - } - else if ($objecttype == 'invoice_supplier') { - $tplpath = 'fourn/facture'; - } - else if ($objecttype == 'order_supplier') { - $tplpath = 'fourn/commande'; - } - - global $linkedObjectBlock; - $linkedObjectBlock = $objects; - - // Output template part (modules that overwrite templates must declare this into descriptor) - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/'.$tplpath.'/tpl')); - foreach($dirtpls as $reldir) - { - $res=@include dol_buildpath($reldir.'/linkedobjectblock.tpl.php'); - if ($res) break; - } - } - - return $num; - } + global $form; + return $form->showLinkedObjectBlock($this); } - /* This is to show add lines */ /** @@ -2684,9 +2640,9 @@ abstract class CommonObject * But for the moment we don't know if it'st possible as we keep a method available on overloaded objects. * * @param string $action Action code - * @param string $seller Object of seller third party - * @param string $buyer Object of buyer third party - * @param string $selected Object line selected + * @param Societe $seller Object of seller third party + * @param Societe $buyer Object of buyer third party + * @param int $selected Object line selected * @param int $dateSelector 1=Show also date range input fields * @return void */ @@ -2799,16 +2755,16 @@ abstract class CommonObject * Return HTML content of a detail line * TODO Move this into an output class file (htmlline.class.php) * - * @param string $action GET/POST action - * @param CommonObjectLine $line Selected object line to output - * @param string $var Is it a an odd line (true) - * @param int $num Number of line (0) - * @param int $i I - * @param int $dateSelector 1=Show also date range input fields - * @param string $seller Object of seller third party - * @param string $buyer Object of buyer third party - * @param string $selected Object line selected - * @param object $extrafieldsline Object of extrafield line attribute + * @param string $action GET/POST action + * @param CommonObjectLine $line Selected object line to output + * @param string $var Is it a an odd line (true) + * @param int $num Number of line (0) + * @param int $i I + * @param int $dateSelector 1=Show also date range input fields + * @param Societe $seller Object of seller third party + * @param Societe $buyer Object of buyer third party + * @param int $selected Object line selected + * @param object $extrafieldsline Object of extrafield line attribute * @return void */ function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) @@ -3083,228 +3039,24 @@ abstract class CommonObject } - /** - * get Margin info - * - * @param string $force_price True of not - * @return mixed Array with info - */ - function getMarginInfos($force_price=false) - { - global $conf; - require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; - - $marginInfos = array( - 'pa_products' => 0, - 'pv_products' => 0, - 'margin_on_products' => 0, - 'margin_rate_products' => '', - 'mark_rate_products' => '', - 'pa_services' => 0, - 'pv_services' => 0, - 'margin_on_services' => 0, - 'margin_rate_services' => '', - 'mark_rate_services' => '', - 'pa_total' => 0, - 'pv_total' => 0, - 'total_margin' => 0, - 'total_margin_rate' => '', - 'total_mark_rate' => '' - ); - - foreach($this->lines as $line) { - if (empty($line->pa_ht) && isset($line->fk_fournprice) && !$force_price) { - $product = new ProductFournisseur($this->db); - if ($product->fetch_product_fournisseur_price($line->fk_fournprice)) - $line->pa_ht = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100); - if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0) - $line->pa_ht += $product->fourn_unitcharges; - } - // si prix d'achat non renseigné et devrait l'être, alors prix achat = prix vente - if ((!isset($line->pa_ht) || $line->pa_ht == 0) && $line->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) { - $line->pa_ht = $line->subprice * (1 - ($line->remise_percent / 100)); - } - - // calcul des marges - if (isset($line->fk_remise_except) && isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT)) { // remise - $pa = $line->qty * $line->pa_ht; - $pv = $line->qty * $line->subprice * (1 - $line->remise_percent / 100); - if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale considérée comme produit - $marginInfos['pa_products'] += $pa; - $marginInfos['pv_products'] += $pv; - $marginInfos['pa_total'] += $pa; - $marginInfos['pv_total'] += $pv; - // if credit note, margin = -1 * (abs(selling_price) - buying_price) - if ($pv < 0) - $marginInfos['margin_on_products'] += -1 * (abs($pv) - $pa); - else - $marginInfos['margin_on_products'] += $pv - $pa; - } - elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service - $marginInfos['pa_services'] += $pa; - $marginInfos['pv_services'] += $pv; - $marginInfos['pa_total'] += $pa; - $marginInfos['pv_total'] += $pv; - // if credit note, margin = -1 * (abs(selling_price) - buying_price) - if ($pv < 0) - $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); - else - $marginInfos['margin_on_services'] += $pv - $pa; - } - elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') { // remise globale prise en compte uniqt sur total - $marginInfos['pa_total'] += $pa; - $marginInfos['pv_total'] += $pv; - } - } - else { - $type=$line->product_type?$line->product_type:$line->fk_product_type; - if ($type == 0) { // product - $pa = $line->qty * $line->pa_ht; - $pv = $line->qty * $line->subprice * (1 - $line->remise_percent / 100); - $marginInfos['pa_products'] += $pa; - $marginInfos['pv_products'] += $pv; - $marginInfos['pa_total'] += $pa; - $marginInfos['pv_total'] += $pv; - // if credit note, margin = -1 * (abs(selling_price) - buying_price) - if ($pv < 0) - $marginInfos['margin_on_products'] += -1 * (abs($pv) - $pa); - else - $marginInfos['margin_on_products'] += $pv - $pa; - } - elseif ($type == 1) { // service - $pa = $line->qty * $line->pa_ht; - $pv = $line->qty * $line->subprice * (1 - $line->remise_percent / 100); - $marginInfos['pa_services'] += $pa; - $marginInfos['pv_services'] += $pv; - $marginInfos['pa_total'] += $pa; - $marginInfos['pv_total'] += $pv; - // if credit note, margin = -1 * (abs(selling_price) - buying_price) - if ($pv < 0) - $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); - else - $marginInfos['margin_on_services'] += $pv - $pa; - } - } - } - if ($marginInfos['pa_products'] > 0) - $marginInfos['margin_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pa_products']; - if ($marginInfos['pv_products'] > 0) - $marginInfos['mark_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pv_products']; - - if ($marginInfos['pa_services'] > 0) - $marginInfos['margin_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pa_services']; - if ($marginInfos['pv_services'] > 0) - $marginInfos['mark_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pv_services']; - - // if credit note, margin = -1 * (abs(selling_price) - buying_price) - if ($marginInfos['pv_total'] < 0) - $marginInfos['total_margin'] = -1 * (abs($marginInfos['pv_total']) - $marginInfos['pa_total']); - else - $marginInfos['total_margin'] = $marginInfos['pv_total'] - $marginInfos['pa_total']; - if ($marginInfos['pa_total'] > 0) - $marginInfos['total_margin_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pa_total']; - if ($marginInfos['pv_total'] > 0) - $marginInfos['total_mark_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pv_total']; - - return $marginInfos; - } - /** * Show the array with all margin infos * - * @param string $force_price Force price - * @return void + * @param boolean $force_price Force price + * @return void + * @deprecated 3.8 Load FormMargin class and make a direct call to displayMarginInfos */ function displayMarginInfos($force_price=false) { - global $langs, $conf, $user; - - if (! empty($user->societe_id)) return; - - if (! $user->rights->margins->liretous) return; - - $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); - - $marginInfo = $this->getMarginInfos($force_price); - - if (! empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) // TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better - { - print $langs->trans('ShowMarginInfos').' : '; - $hidemargininfos = $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW']; - print ''.img_picto($langs->trans("Disabled"),'switch_off').''; - print ''.img_picto($langs->trans("Enabled"),'switch_on').''; - - print ''; - if (!empty($hidemargininfos)) print ''; - } - - print '
'; - print ''; + print ''; print ''; - print ''; + print ''; print ''; - print ''; + print ''; print '  '.$obj->ref_supplier.''.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.''.dol_print_date($obj->datec).''; if($obj->socid) @@ -237,8 +239,8 @@ if ($resql) print ' '; } print ''.dol_print_date($db->jdate($obj->date_contrat)).''.$staticcontrat->LibStatut($obj->statut,3).''.($obj->nb_initial>0?$obj->nb_initial:'').'
'; - print ''; - print ''; - print ''; - if ($conf->global->MARGIN_TYPE == "1") - print ''; - else - print ''; - print ''; - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) - print ''; - if (! empty($conf->global->DISPLAY_MARK_RATES)) - print ''; - print ''; - - if (! empty($conf->product->enabled)) - { - //if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) { - print ''; - print ''; - print ''; - print ''; - print ''; - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) - print ''; - if (! empty($conf->global->DISPLAY_MARK_RATES)) - print ''; - print ''; - } - - if (! empty($conf->service->enabled)) - { - print ''; - print ''; - print ''; - print ''; - print ''; - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) - print ''; - if (! empty($conf->global->DISPLAY_MARK_RATES)) - print ''; - print ''; - } - - if (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) - { - print ''; - print ''; - print ''; - print ''; - print ''; - if (! empty($conf->global->DISPLAY_MARGIN_RATES)) - print ''; - if (! empty($conf->global->DISPLAY_MARK_RATES)) - print ''; - print ''; - } - print '
'.$langs->trans('Margins').''.$langs->trans('SellingPrice').''.$langs->trans('BuyingPrice').''.$langs->trans('CostPrice').''.$langs->trans('Margin').''.$langs->trans('MarginRate').''.$langs->trans('MarkRate').'
'.$langs->trans('MarginOnProducts').''.price($marginInfo['pv_products'], null, null, null, null, $rounding).''.price($marginInfo['pa_products'], null, null, null, null, $rounding).''.price($marginInfo['margin_on_products'], null, null, null, null, $rounding).''.(($marginInfo['margin_rate_products'] == '')?'':price($marginInfo['margin_rate_products'], null, null, null, null, $rounding).'%').''.(($marginInfo['mark_rate_products'] == '')?'':price($marginInfo['mark_rate_products'], null, null, null, null, $rounding).'%').'
'.$langs->trans('MarginOnServices').''.price($marginInfo['pv_services'], null, null, null, null, $rounding).''.price($marginInfo['pa_services'], null, null, null, null, $rounding).''.price($marginInfo['margin_on_services'], null, null, null, null, $rounding).''.(($marginInfo['margin_rate_services'] == '')?'':price($marginInfo['margin_rate_services'], null, null, null, null, $rounding).'%').''.(($marginInfo['mark_rate_services'] == '')?'':price($marginInfo['mark_rate_services'], null, null, null, null, $rounding).'%').'
'.$langs->trans('TotalMargin').''.price($marginInfo['pv_total'], null, null, null, null, $rounding).''.price($marginInfo['pa_total'], null, null, null, null, $rounding).''.price($marginInfo['total_margin'], null, null, null, null, $rounding).''.(($marginInfo['total_margin_rate'] == '')?'':price($marginInfo['total_margin_rate'], null, null, null, null, $rounding).'%').''.(($marginInfo['total_mark_rate'] == '')?'':price($marginInfo['total_mark_rate'], null, null, null, null, $rounding).'%').'
'; + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php'; + $formmargin=new FormMargin($this->db); + $formmargin->displayMarginInfos($this, $force_price); } /** * Add resources to the current object : add entry into llx_element_resources - *Need $this->element & $this->id + * Need $this->element & $this->id * * @param int $resource_id Resource id * @param string $resource_element Resource element @@ -3726,7 +3478,7 @@ abstract class CommonObject { $attributeKey = substr($key,8); // Remove 'options_' prefix $attributeType = $extrafields->attribute_type[$attributeKey]; - $attributeSize = $extrafields->attribute_size[$attributeKey]; + //$attributeSize = $extrafields->attribute_size[$attributeKey]; Not required to insert an extrafield value. Only used for definition. $attributeLabel = $extrafields->attribute_label[$attributeKey]; $attributeParam = $extrafields->attribute_param[$attributeKey]; switch ($attributeType) @@ -3751,19 +3503,19 @@ abstract class CommonObject case 'datetime': $this->array_options[$key]=$this->db->idate($this->array_options[$key]); break; - case 'link': - $param_list=array_keys($attributeParam ['options']); - // 0 : ObjectName - // 1 : classPath - $InfoFieldList = explode(":", $param_list[0]); - dol_include_once($InfoFieldList[1]); - $object = new $InfoFieldList[0]($this->db); - if ($value) - { - $object->fetch(0,$value); - $this->array_options[$key]=$object->id; - } - break; + case 'link': + $param_list=array_keys($attributeParam ['options']); + // 0 : ObjectName + // 1 : classPath + $InfoFieldList = explode(":", $param_list[0]); + dol_include_once($InfoFieldList[1]); + $object = new $InfoFieldList[0]($this->db); + if ($value) + { + $object->fetch(0,$value); + $this->array_options[$key]=$object->id; + } + break; } } $this->db->begin(); @@ -3771,6 +3523,7 @@ abstract class CommonObject $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".$this->id; dol_syslog(get_class($this)."::insertExtraFields delete", LOG_DEBUG); $this->db->query($sql_del); + $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."_extrafields (fk_object"; foreach($this->array_options as $key => $value) { @@ -3825,7 +3578,7 @@ abstract class CommonObject * * @return string */ - function showOptionals($extrafields, $mode='view', $params=0, $keyprefix='') + function showOptionals($extrafields, $mode='view', $params=null, $keyprefix='') { global $_POST, $conf; @@ -3955,15 +3708,16 @@ abstract class CommonObject * This function is meant to be called from replaceThirdparty with the appropiate tables * Column name fk_soc MUST be used to identify thirdparties * - * @param DoliDB $db Database handler - * @param int $origin_id Old thirdparty id - * @param int $dest_id New thirdparty id - * @param array $tables Tables that need to be changed + * @param DoliDB $db Database handler + * @param int $origin_id Old thirdparty id (the thirdparty to delete) + * @param int $dest_id New thirdparty id (the thirdparty that will received element of the other) + * @param array $tables Tables that need to be changed * @return bool */ public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables) { - foreach ($tables as $table) { + foreach ($tables as $table) + { $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; if (!$db->query($sql)) { diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index 07019a0fa1d..ef854a2452e 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -39,6 +39,7 @@ abstract class CommonObjectLine extends CommonObject * Id of the line * @var int * @deprecated Try to use id property as possible (even if field into database is still rowid) + * @see id */ public $rowid; diff --git a/htdocs/core/class/commonorder.class.php b/htdocs/core/class/commonorder.class.php index b4882af8a58..5309b5524ee 100644 --- a/htdocs/core/class/commonorder.class.php +++ b/htdocs/core/class/commonorder.class.php @@ -43,6 +43,7 @@ abstract class CommonOrderLine extends CommonObjectLine * Product ref * @var string * @deprecated Use product_ref + * @see product_ref */ public $ref; @@ -56,6 +57,7 @@ abstract class CommonOrderLine extends CommonObjectLine * Product label * @var string * @deprecated Use product_label + * @see product_label */ public $libelle; @@ -78,7 +80,9 @@ abstract class CommonOrderLine extends CommonObjectLine public $qty; /** + * Unit price * @deprecated + * @see subprice */ var $price; diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 6370062a6a9..13d2881563f 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -404,7 +404,7 @@ class Conf $this->css = "/theme/".$this->theme."/style.css.php"; // conf->email_from = email pour envoi par dolibarr des mails automatiques - $this->email_from = "robot@domain.com"; + $this->email_from = "robot@example.com"; if (! empty($this->global->MAIN_MAIL_EMAIL_FROM)) $this->email_from = $this->global->MAIN_MAIL_EMAIL_FROM; // conf->notification->email_from = email pour envoi par Dolibarr des notifications diff --git a/htdocs/core/class/dolprintipp.class.php b/htdocs/core/class/dolprintipp.class.php index 4b934b331f3..fdd0fc2732c 100644 --- a/htdocs/core/class/dolprintipp.class.php +++ b/htdocs/core/class/dolprintipp.class.php @@ -91,7 +91,14 @@ class dolprintIPP } } // Getting Jobs - $ipp->getJobs(false,0,'completed',false); + try { + $ipp->getJobs(false,0,'completed',false); // May return errors if setup not correct + } + catch(Exception $e) + { + print $e->getMessage(); + } + print ''; print ''; print ""; @@ -102,19 +109,22 @@ class dolprintIPP print ""; print "\n"; $jobs = $ipp->jobs_attributes; - $var = True; + $var = true; //print '
'.print_r($jobs,true).'
'; - foreach ($jobs as $value ) + if (is_array($jobs)) { - $var=!$var; - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + foreach ($jobs as $value) + { + $var=!$var; + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } } print "
IdCancel
'.$value->job_id->_value0.''.$value->job_originating_user_name->_value0.''.$value->printer_uri->_value0.''.$value->job_name->_value0.''.$value->job_state->_value0.''.$value->job_uri->_value0.'
'.$value->job_id->_value0.''.$value->job_originating_user_name->_value0.''.$value->printer_uri->_value0.''.$value->job_name->_value0.''.$value->job_state->_value0.''.$value->job_uri->_value0.'
"; } diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index e2313d157d5..34abeeb8c6e 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -39,7 +39,7 @@ class ExtraFields var $attribute_type; // Tableau contenant le nom des champs en clef et le label de ces champs en value var $attribute_label; - // Tableau contenant le nom des champs en clef et la taille de ces champs en value + // Tableau contenant le nom des champs en clef et la taille/longueur max de ces champs en value var $attribute_size; // Tableau contenant le nom des choix en clef et la valeur de ces choix en value var $attribute_choice; @@ -124,6 +124,7 @@ class ExtraFields if (empty($label)) return -1; if ($elementtype == 'thirdparty') $elementtype='societe'; + if ($elementtype == 'contact') $elementtype='socpeople'; // Create field into database except for separator type which is not stored in database if ($type != 'separate') @@ -169,6 +170,7 @@ class ExtraFields private function create($attrname, $type='varchar', $length=255, $elementtype='member', $unique=0, $required=0, $default_value='',$param='', $perms='', $list=0) { if ($elementtype == 'thirdparty') $elementtype='societe'; + if ($elementtype == 'contact') $elementtype='socpeople'; $table=$elementtype.'_extrafields'; @@ -248,6 +250,7 @@ class ExtraFields global $conf; if ($elementtype == 'thirdparty') $elementtype='societe'; + if ($elementtype == 'contact') $elementtype='socpeople'; // Clean parameters if (empty($pos)) $pos=0; @@ -308,6 +311,7 @@ class ExtraFields function delete($attrname, $elementtype='member') { if ($elementtype == 'thirdparty') $elementtype='societe'; + if ($elementtype == 'contact') $elementtype='socpeople'; $table=$elementtype.'_extrafields'; @@ -342,6 +346,7 @@ class ExtraFields global $conf; if ($elementtype == 'thirdparty') $elementtype='societe'; + if ($elementtype == 'contact') $elementtype='socpeople'; if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { @@ -389,6 +394,7 @@ class ExtraFields function update($attrname,$label,$type,$length,$elementtype,$unique=0,$required=0,$pos=0,$param='',$alwayseditable=0, $perms='',$list='') { if ($elementtype == 'thirdparty') $elementtype='societe'; + if ($elementtype == 'contact') $elementtype='socpeople'; $table=$elementtype.'_extrafields'; @@ -486,6 +492,8 @@ class ExtraFields // Clean parameters if ($elementtype == 'thirdparty') $elementtype='societe'; + if ($elementtype == 'contact') $elementtype='socpeople'; + if (empty($list)) $list=0; if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) @@ -570,6 +578,7 @@ class ExtraFields if ( empty($elementtype) ) return array(); if ($elementtype == 'thirdparty') $elementtype='societe'; + if ($elementtype == 'contact') $elementtype='socpeople'; $array_name_label=array(); diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 47810e204bd..ee7742660c1 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -116,9 +116,9 @@ class HookManager * @param array $parameters Array of parameters * @param Object $object Object to use hooks on * @param string $action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...) - * @return mixed For doActions,formObjectOptions,pdf_xxx: Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 means KO. - * For printSearchForm,printLeftBlock,printTopRightMenu,formAddObjectLine,...: Return HTML string. TODO Deprecated. Must always return an int and things to print into ->resprints. - * Can also return some values into an array ->results. + * @return mixed For 'addreplace hooks (doActions,formObjectOptions,pdf_xxx,...): Return 0 if we want to keep standard actions, >0 if we want to stop standard actions, <0 if KO. + * For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...): Return 0, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. + * All types can also return some values into an array ->results. * $this->error or this->errors are also defined by class called by this function if error. */ function executeHooks($method, $parameters=false, &$object='', &$action='') @@ -135,7 +135,8 @@ class HookManager array( 'addMoreActionsButtons', 'addStatisticLine', - 'doActions', + 'deleteFile', + 'doActions', 'formCreateThirdpartyOptions', 'formObjectOptions', 'formattachOptions', @@ -147,7 +148,7 @@ class HookManager 'formatEvent' ) )) $hooktype='addreplace'; - // Deprecated hook types + // Deprecated hook types ('returnvalue') if (preg_match('/^pdf_/',$method) && $method != 'pdf_writelinedesc') $hooktype='returnvalue'; // pdf_xxx except pdf_writelinedesc are 'returnvalue' hooks. When there is 2 hooks of this type, only last one win. TODO Move them into 'output' or 'addreplace' hooks. if ($method == 'insertExtraFields') { @@ -195,7 +196,7 @@ class HookManager if (isset($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results); if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints; } - // Generic hooks that return a string or array (printSearchForm, printLeftBlock, formAddObjectLine, formBuilddocOptions, ...) + // Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...) else { // TODO. this should be done into the method of hook by returning nothing diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index b4e5a8a0ec0..c236df18199 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -41,6 +41,8 @@ /** * Class to manage generation of HTML components * Only common components must be here. + * + * TODO Merge all function load_cache_* and loadCache* (except load_cache_vatrates) into one generic function loadCacheTable */ class Form { @@ -101,7 +103,7 @@ class Form } } else - { + { $ret.=''; @@ -376,7 +378,7 @@ class Form * @return string Code html du tooltip (texte+picto) * @see Use function textwithpicto if you can. */ - function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img = '', $extracss = '', $notabs = 0, $incbefore = '', $noencodehtmltext = 0) + function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img = '', $extracss = '', $notabs = 2, $incbefore = '', $noencodehtmltext = 0) { global $conf; @@ -391,14 +393,19 @@ class Form $htmltext=str_replace("\r","",$htmltext); $htmltext=str_replace("\n","",$htmltext); + $extrastyle=''; + if ($direction < 0) { $extracss=($extracss?$extracss.' ':'').'inline-block'; $extrastyle='padding: 0px; padding-left: 3px !important;'; } + if ($direction > 0) { $extracss=($extracss?$extracss.' ':'').'inline-block'; $extrastyle='padding: 0px; padding-right: 3px !important;'; } + $htmltext=str_replace('"',""",$htmltext); - if ($tooltipon == 2 || $tooltipon == 3) $paramfortooltipimg=' class="classfortooltip inline-block'.($extracss?' '.$extracss:'').'" style="padding: 0px;" title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td img tag to store tooltip - else $paramfortooltipimg =($extracss?' class="'.$extracss.'"':''); // Attribut to put on td text tag - if ($tooltipon == 1 || $tooltipon == 3) $paramfortooltiptd=' class="classfortooltip inline-block'.($extracss?' '.$extracss:'').'" style="padding: 0px;" title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td tag to store tooltip - else $paramfortooltiptd =($extracss?' class="'.$extracss.'"':''); // Attribut to put on td text tag + if ($tooltipon == 2 || $tooltipon == 3) $paramfortooltipimg=' class="classfortooltip inline-block'.($extracss?' '.$extracss:'').'" style="padding: 0px;'.($extrastyle?' '.$extrastyle:'').'" title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td img tag to store tooltip + else $paramfortooltipimg =($extracss?' class="'.$extracss.'"':'').($extrastyle?' style="'.$extrastyle.'"':''); // Attribut to put on td text tag + if ($tooltipon == 1 || $tooltipon == 3) $paramfortooltiptd=' class="classfortooltip inline-block'.($extracss?' '.$extracss:'').'" style="padding: 0px;'.($extrastyle?' '.$extrastyle:'').'" title="'.($noencodehtmltext?$htmltext:dol_escape_htmltag($htmltext,1)).'"'; // Attribut to put on td tag to store tooltip + else $paramfortooltiptd =($extracss?' class="'.$extracss.'"':'').($extrastyle?' style="'.$extrastyle.'"':''); // Attribut to put on td text tag $s=""; if (empty($notabs)) $s.='
'; $ret.=$langs->trans($text); $ret.='
'; elseif ($notabs == 2) $s.='
'; + // Define value if value is before if ($direction < 0) { $s.='<'.$tag.$paramfortooltipimg; if ($tag == 'td') { @@ -407,16 +414,12 @@ class Form $s.= '>'.$img.''; } // Use another method to help avoid having a space in value in order to use this value with jquery - // TODO add this in css - //if ($text != '') $s.='<'.$tag.$paramfortooltiptd.'>'.(($direction < 0)?' ':'').$text.(($direction > 0)?' ':'').''; - $paramfortooltiptd.= (($direction < 0)?' class="inline-block" style="padding: 0px; padding-left: 3px !important;"':''); - $paramfortooltiptd.= (($direction > 0)?' class="inline-block" style="padding: 0px; padding-right: 3px !important;"':''); + // Define label if ((string) $text != '') $s.='<'.$tag.$paramfortooltiptd.'>'.$text.''; + // Define value if value is after if ($direction > 0) { $s.='<'.$tag.$paramfortooltipimg; - if ($tag == 'td') { - $s .= ' valign="top" width="14"'; - } + if ($tag == 'td') $s .= ' valign="middle" width="14"'; $s.= '>'.$img.''; } if (empty($notabs)) $s.='
'; @@ -437,7 +440,7 @@ class Form * @param int $notabs 0=Include table and tr tags, 1=Do not include table and tr tags, 2=use div, 3=use span * @return string HTML code of text, picto, tooltip */ - function textwithpicto($text, $htmltext, $direction = 1, $type = 'help', $extracss = '', $noencodehtmltext = 0, $notabs = 0) + function textwithpicto($text, $htmltext, $direction = 1, $type = 'help', $extracss = '', $noencodehtmltext = 0, $notabs = 2) { global $conf; @@ -496,14 +499,14 @@ class Form $sql = "SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite"; $sql.= " FROM ".MAIN_DB_PREFIX."c_country"; - $sql.= " WHERE active = 1"; + $sql.= " WHERE active > 0"; //$sql.= " ORDER BY code ASC"; dol_syslog(get_class($this)."::select_country", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { - $out.= ''; $num = $this->db->num_rows($resql); $i = 0; if ($num) @@ -531,7 +534,7 @@ class Form if (empty($row['favorite']) && $atleastonefavorite) { $atleastonefavorite=0; - $out.= ''; + $out.= ''; } if ($selected && $selected != '-1' && ($selected == $row['rowid'] || $selected == $row['code_iso'] || $selected == $row['code_iso3'] || $selected == $row['label']) ) { @@ -554,6 +557,10 @@ class Form dol_print_error($this->db); } + // Make select dynamic + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + $out .= ajax_combobox('select'.$htmlname); + return $out; } @@ -580,7 +587,7 @@ class Form $sql = "SELECT rowid, code"; $sql.= " FROM ".MAIN_DB_PREFIX."c_incoterms"; - $sql.= " WHERE active = 1"; + $sql.= " WHERE active > 0"; $sql.= " ORDER BY code ASC"; dol_syslog(get_class($this)."::select_incoterm", LOG_DEBUG); @@ -707,22 +714,23 @@ class Form /** * Load into cache cache_types_fees, array of types of fees * - * @return int Nb of lines loaded, 0 if already loaded, <0 if ko - * TODO move in DAO class + * @return int Nb of lines loaded, <0 if KO */ function load_cache_types_fees() { global $langs; - $langs->load("trips"); + $num = count($this->cache_types_fees); + if ($num > 0) return 0; // Cache already loaded - if (count($this->cache_types_fees)) return 0; // Cache already load + dol_syslog(__METHOD__, LOG_DEBUG); + + $langs->load("trips"); $sql = "SELECT c.code, c.label"; $sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; - //$sql.= " ORDER BY c.label ASC"; // No sort here, sort must be done after translation + $sql.= " WHERE active > 0"; - dol_syslog(get_class($this).'::load_cache_types_fees', LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -744,7 +752,7 @@ class Form return $num; } else - { + { dol_print_error($this->db); return -1; } @@ -762,7 +770,7 @@ class Form { global $user, $langs; - dol_syslog(get_class($this)."::select_type_fees ".$selected.", ".$htmlname, LOG_DEBUG); + dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); $this->load_cache_types_fees(); @@ -798,11 +806,28 @@ class Form * @param array $ajaxoptions Options for ajax_autocompleter * @param int $forcecombo Force to use combo box * @return string Return select box for thirdparty. + * @deprecated 3.8 Use select_company instead. For exemple $form->select_thirdparty(GETPOST('socid'),'socid','',0) => $form->select_company(GETPOST('socid'),'socid','',1,0,0,array(),0) */ function select_thirdparty($selected='', $htmlname='socid', $filter='', $limit=20, $ajaxoptions=array(), $forcecombo=0) { - global $langs,$conf; + return $this->select_thirdparty_list($selected,$htmlname,$filter,1,0,$forcecombo,array(),'',0,$limit); + } + /** + * Output html form to select a third party + * + * @param string $selected Preselected type + * @param string $htmlname Name of field in form + * @param string $filter optional filters criteras (example: 's.rowid <> x') + * @param int $showempty Add an empty field + * @param int $showtype Show third party type in combolist (customer, prospect or supplier) + * @param int $forcecombo Force to use combo box + * @param array $events Ajax event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) + * @param int $limit Maximum number of elements + * @return string HTML string with select box for thirdparty. + */ + function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array(), $limit=0) + { $out=''; /* TODO Use ajax_autocompleter like for products (not finished) @@ -835,31 +860,12 @@ class Form } else {*/ - $out.=$this->select_thirdparty_list($selected,$htmlname,$filter,1,0,$forcecombo,array(),'',0,$limit); + $out.=$this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit); //} return $out; } - /** - * Output html form to select a third party - * - * @param string $selected Preselected type - * @param string $htmlname Name of field in form - * @param string $filter optional filters criteras (example: 's.rowid <> x') - * @param int $showempty Add an empty field - * @param int $showtype Show third party type in combolist (customer, prospect or supplier) - * @param int $forcecombo Force to use combo box - * @param array $events Event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) - * @param int $limit Maximum number of elements - * @return string HTML string with - * @deprecated Use select_thirdparty instead - */ - function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array(), $limit=0) - { - return $this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit); - } - /** * Output html form to select a third party * @@ -890,7 +896,7 @@ class Form if (! empty($user->societe_id)) $sql.= " AND s.rowid = ".$user->societe_id; if ($filter) $sql.= " AND (".$filter.")"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; - if (! empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND s.status<>0 "; + if (! empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND s.status <> 0"; // Add criteria if ($filterkey && $filterkey != '') { @@ -1117,7 +1123,7 @@ class Form if ($showsoc > 0) $sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX ."societe as s ON s.rowid=sp.fk_soc"; $sql.= " WHERE sp.entity IN (".getEntity('societe', 1).")"; if ($socid > 0) $sql.= " AND sp.fk_soc=".$socid; - if (! empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND sp.statut<>0"; + if (! empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND sp.statut <> 0"; $sql.= " ORDER BY sp.lastname ASC"; dol_syslog(get_class($this)."::select_contacts", LOG_DEBUG); @@ -1223,6 +1229,7 @@ class Form * @param int $force_entity 0 or Id of environment to force * @return void * @deprecated + * @see select_dolusers() */ function select_users($selected='',$htmlname='userid',$show_empty=0,$exclude='',$disabled=0,$include='',$enableonly='',$force_entity=0) { @@ -1244,10 +1251,11 @@ class Form * @param int $showstatus 0=show user status only if status is disabled, 1=always show user status into label, -1=never show user status * @param string $morefilter Add more filters into sql request * @param string $show_every 0=default list, 1=add also a value "Everybody" at beginning of list + * @param string $enableonlytext If option $enableonly is set, we use this text to explain into label why record is disabled. Not used if enableonly is empty. * @return string HTML select string * @see select_dolgroups */ - function select_dolusers($selected='', $htmlname='userid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='', $show_every=0) + function select_dolusers($selected='', $htmlname='userid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0, $maxlength=0, $showstatus=0, $morefilter='', $show_every=0, $enableonlytext='') { global $conf,$user,$langs; @@ -1343,8 +1351,8 @@ class Form $userstatic->lastname=$obj->lastname; $userstatic->firstname=$obj->firstname; - $disableline=0; - if (is_array($enableonly) && count($enableonly) && ! in_array($obj->rowid,$enableonly)) $disableline=1; + $disableline=''; + if (is_array($enableonly) && count($enableonly) && ! in_array($obj->rowid,$enableonly)) $disableline=($enableonlytext?$enableonlytext:'1'); if ((is_object($selected) && $selected->id == $obj->rowid) || (! is_object($selected) && $selected == $obj->rowid)) { @@ -1394,6 +1402,10 @@ class Form } } $out.=($moreinfo?')':''); + if ($disableline && $disableline != '1') + { + $out.=' - '.$disableline; // This is text from $enableonlytext parameter + } $out.= ''; $i++; @@ -1451,12 +1463,12 @@ class Form $out.=''; $out.=''; $out.=$this->select_dolusers('', $htmlname, $show_empty, $exclude, $disabled, $include, $enableonly, $force_entity, $maxlength, $showstatus, $morefilter); - $out.=''; + $out.=' '; } $assignedtouser=array(); if (!empty($_SESSION['assignedtouser'])) { - $assignedtouser=dol_json_decode($_SESSION['assignedtouser'], true); + $assignedtouser=json_decode($_SESSION['assignedtouser'], true); } $nbassignetouser=count($assignedtouser); @@ -2312,19 +2324,22 @@ class Form /** * Charge dans cache la liste des conditions de paiements possibles * - * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko + * @return int Nb of lines loaded, <0 if KO */ function load_cache_conditions_paiements() { global $langs; - if (count($this->cache_conditions_paiements)) return 0; // Cache deja charge + $num = count($this->cache_conditions_paiements); + if ($num > 0) return 0; // Cache already loaded - $sql = "SELECT rowid, code, libelle"; + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = "SELECT rowid, code, libelle as label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_payment_term'; - $sql.= " WHERE active=1"; + $sql.= " WHERE active > 0"; $sql.= " ORDER BY sortorder"; - dol_syslog(get_class($this).'::load_cache_conditions_paiements', LOG_DEBUG); + $resql = $this->db->query($sql); if ($resql) { @@ -2335,14 +2350,18 @@ class Form $obj = $this->db->fetch_object($resql); // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut - $libelle=($langs->trans("PaymentConditionShort".$obj->code)!=("PaymentConditionShort".$obj->code)?$langs->trans("PaymentConditionShort".$obj->code):($obj->libelle!='-'?$obj->libelle:'')); + $label=($langs->trans("PaymentConditionShort".$obj->code)!=("PaymentConditionShort".$obj->code)?$langs->trans("PaymentConditionShort".$obj->code):($obj->label!='-'?$obj->label:'')); $this->cache_conditions_paiements[$obj->rowid]['code'] =$obj->code; - $this->cache_conditions_paiements[$obj->rowid]['label']=$libelle; + $this->cache_conditions_paiements[$obj->rowid]['label']=$label; $i++; } - return 1; + + //$this->cache_conditions_paiements=dol_sort_array($this->cache_conditions_paiements, 'label'); // We use the sortorder + + return $num; } - else { + else + { dol_print_error($this->db); return -1; } @@ -2351,19 +2370,21 @@ class Form /** * Charge dans cache la liste des délais de livraison possibles * - * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko + * @return int Nb of lines loaded, <0 if KO */ function load_cache_availability() { global $langs; - if (count($this->cache_availability)) return 0; // Cache deja charge + $num = count($this->cache_availability); + if ($num > 0) return 0; // Cache already loaded + + dol_syslog(__METHOD__, LOG_DEBUG); $sql = "SELECT rowid, code, label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_availability'; - $sql.= " WHERE active=1"; - $sql.= " ORDER BY rowid"; - dol_syslog(get_class($this).'::load_cache_availability', LOG_DEBUG); + $sql.= " WHERE active > 0"; + $resql = $this->db->query($sql); if ($resql) { @@ -2379,9 +2400,13 @@ class Form $this->cache_availability[$obj->rowid]['label']=$label; $i++; } - return 1; + + $this->cache_availability = dol_sort_array($this->cache_availability, 'label'); + + return $num; } - else { + else + { dol_print_error($this->db); return -1; } @@ -2402,6 +2427,8 @@ class Form $this->load_cache_availability(); + dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); + print ''; @@ -2595,7 +2631,7 @@ class Form { global $langs,$user; - dol_syslog(get_class($this)."::select_type_paiements ".$selected.", ".$htmlname.", ".$filtertype.", ".$format,LOG_DEBUG); + dol_syslog(__METHOD__." ".$selected.", ".$htmlname.", ".$filtertype.", ".$format, LOG_DEBUG); $filterarray=array(); if ($filtertype == 'CRDT') $filterarray=array(0,2,3); @@ -2635,26 +2671,13 @@ class Form /** - * Selection HT or TTC + * Selection HT or TTC * - * @param string $selected Id pre-selectionne - * @param string $htmlname Nom de la zone select - * @return void + * @param string $selected Id pre-selectionne + * @param string $htmlname Nom de la zone select + * @return string Code of HTML select to chose tax or not */ - function select_PriceBaseType($selected='',$htmlname='price_base_type') - { - print $this->load_PriceBaseType($selected,$htmlname); - } - - - /** - * Selection HT or TTC - * - * @param string $selected Id pre-selectionne - * @param string $htmlname Nom de la zone select - * @return void - */ - function load_PriceBaseType($selected='',$htmlname='price_base_type') + function selectPriceBaseType($selected='',$htmlname='price_base_type') { global $langs; @@ -2699,9 +2722,9 @@ class Form $langs->load("admin"); $langs->load("deliveries"); - $sql = "SELECT rowid, code, libelle"; + $sql = "SELECT rowid, code, libelle as label"; $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode"; - $sql.= " WHERE active = 1"; + $sql.= " WHERE active > 0"; if ($filtre) $sql.=" AND ".$filtre; $sql.= " ORDER BY libelle ASC"; @@ -2722,7 +2745,7 @@ class Form } else { print ''; $i++; } @@ -2774,12 +2797,12 @@ class Form /** * Creates HTML last in cycle situation invoices selector * - * @param string $selected Preselected ID - * @param int $socid Company ID + * @param string $selected Preselected ID + * @param int $socid Company ID * * @return string HTML select */ - function load_situation_invoices($selected = '', $socid = '') + function selectSituationInvoices($selected = '', $socid = 0) { global $langs; @@ -2787,7 +2810,7 @@ class Form $opt = ''; $sql = 'SELECT rowid, facnumber, situation_cycle_ref, situation_counter, situation_final, fk_soc FROM ' . MAIN_DB_PREFIX . 'facture WHERE situation_counter>=1'; - $sql .= ' order by situation_cycle_ref, situation_counter desc'; + $sql.= ' ORDER by situation_cycle_ref, situation_counter desc'; $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { // Last seen cycle @@ -2813,10 +2836,13 @@ class Form } } } - } else { + } + else + { dol_syslog("Error sql=" . $sql . ", error=" . $this->error, LOG_ERR); } - if ($opt == '') { + if ($opt == '') + { $opt = ''; } return $opt; @@ -2825,7 +2851,7 @@ class Form /** * Creates HTML units selector (code => label) * - * @param string $selected Preselected code ('km', 'm', 'l', 'p', ...) + * @param string $selected Preselected Unit ID * @param string $htmlname Select name * @param int $showempty Add a nempty line * @return string HTML select @@ -2838,7 +2864,9 @@ class Form $return= ''; @@ -3025,6 +3053,7 @@ class Form * @param int $width Force width of box * @return void * @deprecated + * @see formconfirm() */ function form_confirm($page, $title, $question, $action, $formquestion='', $selectedchoice="", $useajax=0, $height=170, $width=500) { @@ -3082,7 +3111,7 @@ class Form // Now add questions $more.=''."\n"; - $more.=''."\n"; + $more.=''."\n"; foreach ($formquestion as $key => $input) { if (is_array($input) && ! empty($input)) @@ -3091,15 +3120,15 @@ class Form if ($input['type'] == 'text') { - $more.=''."\n"; + $more.=''."\n"; } else if ($input['type'] == 'password') { - $more.=''."\n"; + $more.=''."\n"; } else if ($input['type'] == 'select') { - $more.=''."\n"; @@ -3107,13 +3136,13 @@ class Form else if ($input['type'] == 'checkbox') { $more.=''; - $more.=''; - $more.=''."\n"; } @@ -3508,9 +3537,9 @@ class Form * * @param string $page Page * @param string $selected Id of user preselected - * @param string $htmlname Name of input html field - * @param array $exclude List of users id to exclude - * @param array $include List of users id to include + * @param string $htmlname Name of input html field. If 'none', we just output the user link. + * @param array $exclude List of users id to exclude + * @param array $include List of users id to include * @return void */ function form_users($page, $selected='', $htmlname='userid', $exclude='', $include='') @@ -3530,12 +3559,10 @@ class Form print '
'.(! empty($formquestion['text'])?$formquestion['text']:'').'
'.(! empty($formquestion['text'])?$formquestion['text']:'').'
'.$input['label'].'
'.$input['label'].'
'.$input['label'].'
'.$input['label'].'
'; + $more.='
'; if (! empty($input['label'])) $more.=$input['label'].''; $more.=$this->selectarray($input['name'],$input['values'],$input['default'],1); $more.='
'.$input['label'].' '; + $more.=''.$input['label'].' '; $more.=''; else $more.=' '; + $more.='
'; + if (! empty($input['label'])) $more.=$input['label'].''; $more.=$input['value']; $more.='
'; } else - { + { if ($selected) { require_once DOL_DOCUMENT_ROOT .'/user/class/user.class.php'; - //$this->load_cache_contacts(); - //print $this->cache_contacts[$selected]; $theuser=new User($this->db); $theuser->fetch($selected); print $theuser->getNomUrl(1); @@ -3646,12 +3673,12 @@ class Form /** - * Affiche formulaire de selection des contacts + * Show forms to select a contact * - * @param string $page Page - * @param Societe $societe Third party - * @param int $selected Id contact pre-selectionne - * @param string $htmlname Nom du formulaire select + * @param string $page Page + * @param Societe $societe Filter on third party + * @param int $selected Id contact pre-selectionne + * @param string $htmlname Name of HTML select. If 'none', we just show contact link. * @return void */ function form_contacts($page, $societe, $selected='', $htmlname='contactid') @@ -3681,8 +3708,6 @@ class Form if ($selected) { require_once DOL_DOCUMENT_ROOT .'/contact/class/contact.class.php'; - //$this->load_cache_contacts(); - //print $this->cache_contacts[$selected]; $contact=new Contact($this->db); $contact->fetch($selected); print $contact->getFullName($langs); @@ -3798,12 +3823,14 @@ class Form global $langs; $num = count($this->cache_vatrates); - if ($num > 0) return $num; // Cache deja charge + if ($num > 0) return $num; // Cache already loaded - $sql = "SELECT DISTINCT t.taux, t.recuperableonly"; + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = "SELECT DISTINCT t.taux, t.recuperableonly"; $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; $sql.= " WHERE t.fk_pays = c.rowid"; - $sql.= " AND t.active = 1"; + $sql.= " AND t.active > 0"; $sql.= " AND c.code IN (".$country_code.")"; $sql.= " ORDER BY t.taux ASC, t.recuperableonly ASC"; @@ -3837,7 +3864,8 @@ class Form } /** - * Output an HTML select vat rate + * Output an HTML select vat rate. + * The name of this function should be selectVat. We keep bad name for compatibility purpose. * * @param string $htmlname Name of html select field * @param float $selectedrate Force preselected vat rate. Use '' for no forcing. @@ -4244,6 +4272,7 @@ class Form $hourSelected=0; $minSelected=0; + // Hours if ($iSecond != '') { require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; @@ -4274,6 +4303,7 @@ class Form $retstring.=' '.$langs->trans('HourShort'); + // Minutes if ($minunderhours) $retstring.='
'; else $retstring.=" "; @@ -4327,24 +4357,26 @@ class Form global $conf, $langs; // Do we want a multiselect ? - $multiselect = 0; - if (preg_match('/^multi/',$htmlname)) $multiselect = 1; + //$jsbeautify = 0; + //if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1; + $jsbeautify = 1; if ($value_as_key) $array=array_combine($array, $array); $out=''; // Add code for jquery to use multiselect - if ($addjscombo && empty($conf->dol_use_jmobile) && $multiselect) + if ($addjscombo && empty($conf->dol_use_jmobile) && $jsbeautify) { + $minLengthToAutocomplete=0; $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT')?constant('REQUIRE_JQUERY_MULTISELECT'):'select2':$conf->global->MAIN_USE_JQUERY_MULTISELECT; $out.=' '; @@ -4419,7 +4451,7 @@ class Form { $out = ''; - // Add code for jquery to use multiselect + // Add code for jquery to use select2 if ($addjscombo && empty($conf->dol_use_jmobile)) { $tmpplugin='select2'; @@ -4605,6 +4637,236 @@ class Form } + /** + * Show linked object block. + * + * @param CommonObject $object Object we want to show links to + * @return int <0 if KO, >0 if OK + */ + function showLinkedObjectBlock($object) + { + global $conf,$langs,$hookmanager; + global $bc; + + $object->fetchObjectLinked(); + + // Bypass the default method + $hookmanager->initHooks(array('commonobject')); + $parameters=array(); + $reshook=$hookmanager->executeHooks('showLinkedObjectBlock',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + + if (empty($reshook)) + { + $num = count($object->linkedObjects); + + foreach($object->linkedObjects as $objecttype => $objects) + { + $tplpath = $element = $subelement = $objecttype; + + if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) + { + $element = $regs[1]; + $subelement = $regs[2]; + $tplpath = $element.'/'.$subelement; + } + + // To work with non standard path + if ($objecttype == 'facture') { + $tplpath = 'compta/'.$element; + if (empty($conf->facture->enabled)) continue; // Do not show if module disabled + } + else if ($objecttype == 'propal') { + $tplpath = 'comm/'.$element; + if (empty($conf->propal->enabled)) continue; // Do not show if module disabled + } + else if ($objecttype == 'askpricesupplier') { + $tplpath = 'comm/'.$element; + if (empty($conf->askpricesupplier->enabled)) continue; // Do not show if module disabled + } + else if ($objecttype == 'shipping' || $objecttype == 'shipment') { + $tplpath = 'expedition'; + if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled + } + else if ($objecttype == 'delivery') { + $tplpath = 'livraison'; + if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled + } + else if ($objecttype == 'invoice_supplier') { + $tplpath = 'fourn/facture'; + } + else if ($objecttype == 'order_supplier') { + $tplpath = 'fourn/commande'; + } + + global $linkedObjectBlock; + $linkedObjectBlock = $objects; + + // Output template part (modules that overwrite templates must declare this into descriptor) + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/'.$tplpath.'/tpl')); + foreach($dirtpls as $reldir) + { + $res=@include dol_buildpath($reldir.'/linkedobjectblock.tpl.php'); + if ($res) break; + } + } + + return $num; + } + } + + /** + * Show block with links to link to other objects. + * + * @param CommonObject $object Object we want to show links to + * @param array $restrictlinksto Restrict links to some elements, for exemple array('order') or array('supplier_order') + * @return int <0 if KO, >0 if OK + */ + function showLinkToObjectBlock($object, $restrictlinksto=array()) + { + global $conf, $langs, $hookmanager; + global $bc; + + $linktoelem=''; + + if (! is_object($object->thirdparty)) $object->fetch_thirdparty(); + + + if (((! is_array($restrictlinksto)) || in_array('order',$restrictlinksto)) + && ! empty($conf->commande->enabled)) + { + $linktoelem.=($linktoelem?'   ':'').'' . $langs->trans('LinkedOrder') . ''; + + print ' + + '; + + print '
global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display:none"':'').'>'; + + $sql = "SELECT s.rowid as socid, s.nom as name, s.client, c.rowid, c.ref, c.ref_client, c.total_ht"; + $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; + $sql .= ", " . MAIN_DB_PREFIX . "commande as c"; + $sql .= ' WHERE c.fk_soc = s.rowid AND c.fk_soc = ' . $object->thirdparty->id . ''; + + $resqlorderlist = $this->db->query($sql); + if ($resqlorderlist) + { + $num = $this->db->num_rows($resqlorderlist); + $i = 0; + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + while ($i < $num) + { + $objp = $this->db->fetch_object($resqlorderlist); + + $var = ! $var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $i ++; + } + print '
' . $langs->trans("Ref") . '' . $langs->trans("RefCustomer") . '' . $langs->trans("AmountHTShort") . '' . $langs->trans("Company") . '
'; + print ''; + print '' . $objp->ref . '' . $objp->ref_client . '' . price($objp->total_ht) . '' . $objp->name . '
'; + print '
     
'; + print '
'; + $this->db->free($resqlorderlist); + } else { + dol_print_error($this->db); + } + + print '
'; + } + + if (((! is_array($restrictlinksto)) || in_array('supplier_order',$restrictlinksto)) + && ! empty($conf->fournisseur->enabled)) + { + $linktoelem.=($linktoelem?'   ':'').'' . $langs->trans('LinkedOrder') . ''; + + print ' + + '; + + print '
global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display:none"':'').'>'; + + $sql = "SELECT s.rowid as socid, s.nom as name, s.client, c.rowid, c.ref, c.ref_supplier, c.total_ht"; + $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; + $sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseur as c"; + $sql .= ' WHERE c.fk_soc = s.rowid AND c.fk_soc = ' . $object->thirdparty->id; + + $resqlorderlist = $this->db->query($sql); + if ($resqlorderlist) + { + $num = $this->db->num_rows($resqlorderlist); + $i = 0; + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + while ($i < $num) { + $objp = $this->db->fetch_object($resqlorderlist); + if ($objp->socid == $societe->id) { + $var = ! $var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + + $i ++; + } + print '
' . $langs->trans("Ref") . '' . $langs->trans("RefSupplier") . '' . $langs->trans("AmountHTShort") . '' . $langs->trans("Company") . '
'; + print ''; + print '' . $objp->ref . '' . $objp->ref_supplier . '' . price($objp->total_ht) . '' . $objp->name . '
'; + print '
 
'; + print '
'; + $this->db->free($resqlorderlist); + } else { + dol_print_error($this->db); + } + + print '
'; + } + + + return $linktoelem; + } + /** * Return an html string with a select combo box to choose yes or no * @@ -4701,15 +4963,15 @@ class Form * To add a particular filter on select, you must set $object->next_prev_filter to SQL criteria. * * @param object $object Object to show - * @param string $paramid Name of parameter to use to name the id into the URL link - * @param string $morehtml More html content to output just before the nav bar + * @param string $paramid Name of parameter to use to name the id into the URL link + * @param string $morehtml More html content to output just before the nav bar * @param int $shownav Show Condition (navigation is shown if value is 1) - * @param string $fieldid Nom du champ en base a utiliser pour select next et previous - * @param string $fieldref Nom du champ objet ref (object->ref) a utiliser pour select next et previous - * @param string $morehtmlref Code html supplementaire a afficher apres ref - * @param string $moreparam More param to add in nav link url. + * @param string $fieldid Nom du champ en base a utiliser pour select next et previous (we make the select max and min on this field) + * @param string $fieldref Nom du champ objet ref (object->ref) a utiliser pour select next et previous + * @param string $morehtmlref Code html supplementaire a afficher apres ref + * @param string $moreparam More param to add in nav link url. * @param int $nodbprefix Do not include DB prefix to forge table name - * @return string Portion HTML avec ref + boutons nav + * @return string Portion HTML avec ref + boutons nav */ function showrefnav($object,$paramid,$morehtml='',$shownav=1,$fieldid='rowid',$fieldref='ref',$morehtmlref='',$moreparam='',$nodbprefix=0) { @@ -4722,33 +4984,47 @@ class Form //print "paramid=$paramid,morehtml=$morehtml,shownav=$shownav,$fieldid,$fieldref,$morehtmlref,$moreparam"; $object->load_previous_next_ref((isset($object->next_prev_filter)?$object->next_prev_filter:''),$fieldid,$nodbprefix); - $previous_ref = $object->ref_previous?''.(empty($conf->dol_use_jmobile)?img_picto($langs->trans("Previous"),'previous.png'):' ').'':''; - $next_ref = $object->ref_next?''.(empty($conf->dol_use_jmobile)?img_picto($langs->trans("Next"),'next.png'):' ').'':''; + //$previous_ref = $object->ref_previous?''.(empty($conf->dol_use_jmobile)?img_picto($langs->trans("Previous"),'previous.png'):' ').'':''; + //$next_ref = $object->ref_next?''.(empty($conf->dol_use_jmobile)?img_picto($langs->trans("Next"),'next.png'):' ').'':''; + $previous_ref = $object->ref_previous?''.(empty($conf->dol_use_jmobile)?'<':' ').'':''; + $next_ref = $object->ref_next?''.(empty($conf->dol_use_jmobile)?'>':' ').'':''; //print "xx".$previous_ref."x".$next_ref; - if ($previous_ref || $next_ref || $morehtml) { - $ret.='
'; - } + //if ($previous_ref || $next_ref || $morehtml) { + //$ret.=''; - $ret.=''; + //$ret.='
'; + $ret.='
'; + //} $ret.=dol_htmlentities($object->$fieldref); if ($morehtmlref) { $ret.=' '.$morehtmlref; } + $ret.='
'; + if ($previous_ref || $next_ref || $morehtml) + { + $ret.='
'.$morehtml; + //$ret.=''.$morehtml; + $ret.='
  • '.$morehtml.'
  • '; } if ($shownav && ($previous_ref || $next_ref)) { - $ret.='
    '.$previous_ref.''.$next_ref; + //$ret.=''.$previous_ref.''.$next_ref; + $ret.=''; + $ret.=''; } if ($previous_ref || $next_ref || $morehtml) { - $ret.='
    '; + //$ret.='
    '; + $ret.='
    '; } + $ret.='
    '; + return $ret; } @@ -4788,11 +5064,14 @@ class Form * @param string $modulepart Key to define module concerned ('societe', 'userphoto', 'memberphoto') * @param object $object Object containing data to retrieve file name * @param int $width Width of photo + * @param int $height Height of photo (auto if 0) + * @param int $caneditfield Add edit fields + * @param string $cssclass CSS name to use on img for photo * @return string HTML code to output photo */ - static function showphoto($modulepart,$object,$width=100) + static function showphoto($modulepart, $object, $width=100, $height=0, $caneditfield=0, $cssclass='photowithmargin') { - global $conf; + global $conf,$langs; $entity = (! empty($object->entity) ? $object->entity : $conf->entity); $id = (! empty($object->id) ? $object->id : $object->rowid); @@ -4819,7 +5098,7 @@ class Form if ($object->photo) $file=get_exdir($id, 2, 0, 0, $object, 'invoice_supplier').'photos/'.$object->photo; if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility $email=$object->email; - }else { + } else { $dir=$conf->$modulepart->dir_output; if ($object->photo) $file=get_exdir($id, 2, 0, 0, $adherent, 'member').'photos/'.$object->photo; if (! empty($conf->global->MAIN_OLD_IMAGE_LINKS)) $altfile=$object->id.".jpg"; // For backward compatibility @@ -4831,30 +5110,51 @@ class Form $cache='0'; if ($file && file_exists($dir."/".$file)) { - // TODO Link to large image $ret.=''; - $ret.=''; + $ret.='Photo'; $ret.=''; } else if ($altfile && file_exists($dir."/".$altfile)) { $ret.=''; - $ret.=''; + $ret.='Photo alt'; $ret.=''; } else - { - if (! empty($conf->gravatar->enabled) && $email) + { + $nophoto='/public/theme/common/nophoto.jpg'; + if (in_array($modulepart,array('userphoto','contact'))) // For module thar are "physical" users + { + $nophoto='/public/theme/common/user_anonymous.png'; + if ($object->gender == 'man') $nophoto='/public/theme/common/user_man.png'; + if ($object->gender == 'woman') $nophoto='/public/theme/common/user_woman.png'; + } + + if (! empty($conf->gravatar->enabled) && $email) { + /** + * @see https://gravatar.com/site/implement/images/php/ + */ global $dolibarr_main_url_root; $ret.=''; - $ret.='Photo found on Gravatar'; // gravatar need md5 hash + $ret.='Gravatar avatar'; // gravatar need md5 hash } else - { - $ret.='No photo'; + { + $ret.='No photo'; } } + + if ($caneditfield) + { + if ($object->photo) $ret.="
    \n"; + $ret.=''; + if ($object->photo) $ret.=''; + $ret.=''; + $ret.=''; + $ret.='
    '.$langs->trans("Delete").'

    '.$langs->trans("PhotoFile").'
    '; + } + } else dol_print_error('','Call of showphoto with wrong parameters'); diff --git a/htdocs/core/class/html.formadmin.class.php b/htdocs/core/class/html.formadmin.class.php index e5d8fa5688e..d3ffa569a7a 100644 --- a/htdocs/core/class/html.formadmin.class.php +++ b/htdocs/core/class/html.formadmin.class.php @@ -105,6 +105,10 @@ class FormAdmin } $out.= ''; + // Make select dynamic + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + $out.= ajax_combobox($htmlname); + return $out; } diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php index 4f600ac0705..a005fb2b228 100644 --- a/htdocs/core/class/html.formcompany.class.php +++ b/htdocs/core/class/html.formcompany.class.php @@ -210,6 +210,7 @@ class FormCompany * @param string $country_codeid Country code or id: 0=list for all countries, otherwise country code or country rowid to show * @param string $htmlname Id of department * @return string String with HTML select + * @see select_country */ function select_state($selected='',$country_codeid=0, $htmlname='state_id') { @@ -234,7 +235,7 @@ class FormCompany $result=$this->db->query($sql); if ($result) { - if (!empty($htmlname)) $out.= ''; if ($country_codeid) $out.= ''; $num = $this->db->num_rows($result); $i = 0; @@ -277,13 +278,17 @@ class FormCompany } } if (! empty($htmlname)) $out.= ''; - if (! empty($htmlname) && $user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); + if (! empty($htmlname) && $user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); } else { dol_print_error($this->db); } + // Make select dynamic + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + $out .= ajax_combobox($htmlname); + return $out; } @@ -418,6 +423,7 @@ class FormCompany * @param string $filter Add a SQL filter on list * @return void * @deprecated Use print xxx->select_juridicalstatus instead + * @see select_juridicalstatus() */ function select_forme_juridique($selected='', $country_codeid=0, $filter='') { @@ -431,9 +437,10 @@ class FormCompany * @param string $selected Preselected code of juridical type * @param int $country_codeid 0=list for all countries, otherwise list only country requested * @param string $filter Add a SQL filter on list + * @param string $htmlname HTML name of select * @return string String with HTML select */ - function select_juridicalstatus($selected='', $country_codeid=0, $filter='') + function select_juridicalstatus($selected='', $country_codeid=0, $filter='', $htmlname='forme_juridique_code') { global $conf,$langs,$user; $langs->load("dict"); @@ -454,7 +461,7 @@ class FormCompany if ($resql) { $out.= '
    '; - $out.= ''; if ($country_codeid) $out.= ''; // When country_codeid is set, we force to add an empty line because it does not appears from select. When not set, we already get the empty line from select. $num = $this->db->num_rows($resql); @@ -488,7 +495,7 @@ class FormCompany // Show break when we are in multi country mode if (empty($country_codeid) && $val['country_code']) { - $out.= '\n"; + $out.= '\n"; $country=$val['country']; } } @@ -507,7 +514,12 @@ class FormCompany } } $out.= ''; - if ($user->admin) $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); + if ($user->admin) $out.= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); + + // Make select dynamic + include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; + $out .= ajax_combobox($htmlname); + $out.= '
    '; } else diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 926ee8a337a..699060afcfc 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -249,7 +249,7 @@ class FormFile * @param string $modelselected Model to preselect by default * @param string $allowgenifempty Allow generation even if list of template ($genallowed) is empty (show however a warning) * @param string $forcenomultilang Do not show language option (even if MAIN_MULTILANGS defined) - * @param int $iconPDF Obsolete, see getDocumentsLink + * @param int $iconPDF Deprecated, see getDocumentsLink * @param int $maxfilenamelength Max length for filename shown * @param string $noform Do not output html form tags * @param string $param More param on http links @@ -261,6 +261,11 @@ class FormFile */ function showdocuments($modulepart,$modulesubdir,$filedir,$urlsource,$genallowed,$delallowed=0,$modelselected='',$allowgenifempty=1,$forcenomultilang=0,$iconPDF=0,$maxfilenamelength=28,$noform=0,$param='',$title='',$buttonlabel='',$codelang='',$morepicto='') { + // Deprecation warning + if (0 !== $iconPDF) { + dol_syslog(__METHOD__ . ": passing iconPDF parameter is deprecated", LOG_WARNING); + } + global $langs, $conf, $user, $hookmanager; global $form, $bc; @@ -684,7 +689,7 @@ class FormFile $out=''; $this->numoffiles=0; - $file_list=dol_dir_list($filedir, 'files', 0, preg_quote(basename($modulesubdir).'.pdf','/'), '\.meta$|\.png$'); + $file_list=dol_dir_list($filedir, 'files', 0, preg_quote(basename($modulesubdir),'/').'[^\-]+', '\.meta$|\.png$'); // For ajax treatment $out.= '
    '.img_picto('', 'refresh').'
    '."\n"; @@ -713,7 +718,7 @@ class FormFile $mime=dol_mimetype($relativepath,'',0); if (preg_match('/text/',$mime)) $out.= ' target="_blank"'; $out.= '>'; - $out.= img_pdf($file["name"],2); + $out.= img_mime($relativepath, $file["name"]); $out.= ''."\n"; $this->numoffiles++; diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index b9d5048db74..4e1a8ffc0c5 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -48,7 +48,16 @@ class FormMail extends Form var $withsubstit; // Show substitution array var $withfrom; - var $withto; // Show recipient emails + /** + * @var int + * @deprecated Fill withto with array before calling method. + * @see withto + */ + public $withtosocid; + /** + * @var int|int[] + */ + public $withto; // Show recipient emails var $withtofree; // Show free text for recipient emails var $withtocc; var $withtoccc; @@ -275,7 +284,7 @@ class FormMail extends Form $out.= "\n\n"; if ($this->withform == 1) { - $out.= '
    '."\n"; + $out.= ''."\n"; $out.= ''; $out.= ''; $out.= ''; @@ -703,6 +712,23 @@ class FormMail extends Form $out.= ''."\n"; if ($this->withform == 1) $out.= '
    '."\n"; + + // Disable enter key if option MAIN_MAILFORM_DISABLE_ENTER is set + if (! empty($conf->global->MAIN_MAILFORM_DISABLE_ENTERKEY)) + { + $out.= ''; + } + $out.= "\n"; return $out; diff --git a/htdocs/core/class/html.formmargin.class.php b/htdocs/core/class/html.formmargin.class.php new file mode 100644 index 00000000000..a52238be1b9 --- /dev/null +++ b/htdocs/core/class/html.formmargin.class.php @@ -0,0 +1,273 @@ + + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/core/class/html.formmargin.class.php + * \ingroup core + * \brief Fichier de la classe des fonctions predefinie de composants html autre + */ + + +/** + * Classe permettant la generation de composants html autre + * Only common components are here. + */ +class FormMargin +{ + var $db; + var $error; + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db) + { + $this->db = $db; + + return 1; + } + + + + /** + * get array with margin information from lines of object + * + * @param CommonObject $object Object we want to get margin information for + * @param boolean $force_price True of not + * @return array Array with info + */ + function getMarginInfosArray($object, $force_price=false) + { + global $conf, $db; + + // Default returned array + $marginInfos = array( + 'pa_products' => 0, + 'pv_products' => 0, + 'margin_on_products' => 0, + 'margin_rate_products' => '', + 'mark_rate_products' => '', + 'pa_services' => 0, + 'pv_services' => 0, + 'margin_on_services' => 0, + 'margin_rate_services' => '', + 'mark_rate_services' => '', + 'pa_total' => 0, + 'pv_total' => 0, + 'total_margin' => 0, + 'total_margin_rate' => '', + 'total_mark_rate' => '' + ); + + foreach($object->lines as $line) + { + if (empty($line->pa_ht) && isset($line->fk_fournprice) && !$force_price) + { + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; + $product = new ProductFournisseur($db); + if ($product->fetch_product_fournisseur_price($line->fk_fournprice)) + $line->pa_ht = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100); + if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0) + $line->pa_ht += $product->fourn_unitcharges; + } + // si prix d'achat non renseigné et devrait l'être, alors prix achat = prix vente + if ((!isset($line->pa_ht) || $line->pa_ht == 0) && $line->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) { + $line->pa_ht = $line->subprice * (1 - ($line->remise_percent / 100)); + } + + // calcul des marges + if (isset($line->fk_remise_except) && isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT)) { // remise + $pa = $line->qty * $line->pa_ht; + $pv = $line->qty * $line->subprice * (1 - $line->remise_percent / 100); + if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') { // remise globale considérée comme produit + $marginInfos['pa_products'] += $pa; + $marginInfos['pv_products'] += $pv; + $marginInfos['pa_total'] += $pa; + $marginInfos['pv_total'] += $pv; + // if credit note, margin = -1 * (abs(selling_price) - buying_price) + if ($pv < 0) + $marginInfos['margin_on_products'] += -1 * (abs($pv) - $pa); + else + $marginInfos['margin_on_products'] += $pv - $pa; + } + elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') { // remise globale considérée comme service + $marginInfos['pa_services'] += $pa; + $marginInfos['pv_services'] += $pv; + $marginInfos['pa_total'] += $pa; + $marginInfos['pv_total'] += $pv; + // if credit note, margin = -1 * (abs(selling_price) - buying_price) + if ($pv < 0) + $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); + else + $marginInfos['margin_on_services'] += $pv - $pa; + } + elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') { // remise globale prise en compte uniqt sur total + $marginInfos['pa_total'] += $pa; + $marginInfos['pv_total'] += $pv; + } + } + else { + $type=$line->product_type?$line->product_type:$line->fk_product_type; + if ($type == 0) { // product + $pa = $line->qty * $line->pa_ht; + $pv = $line->qty * $line->subprice * (1 - $line->remise_percent / 100); + $marginInfos['pa_products'] += $pa; + $marginInfos['pv_products'] += $pv; + $marginInfos['pa_total'] += $pa; + $marginInfos['pv_total'] += $pv; + // if credit note, margin = -1 * (abs(selling_price) - buying_price) + if ($pv < 0) + $marginInfos['margin_on_products'] += -1 * (abs($pv) - $pa); + else + $marginInfos['margin_on_products'] += $pv - $pa; + } + elseif ($type == 1) { // service + $pa = $line->qty * $line->pa_ht; + $pv = $line->qty * $line->subprice * (1 - $line->remise_percent / 100); + $marginInfos['pa_services'] += $pa; + $marginInfos['pv_services'] += $pv; + $marginInfos['pa_total'] += $pa; + $marginInfos['pv_total'] += $pv; + // if credit note, margin = -1 * (abs(selling_price) - buying_price) + if ($pv < 0) + $marginInfos['margin_on_services'] += -1 * (abs($pv) - $pa); + else + $marginInfos['margin_on_services'] += $pv - $pa; + } + } + } + if ($marginInfos['pa_products'] > 0) + $marginInfos['margin_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pa_products']; + if ($marginInfos['pv_products'] > 0) + $marginInfos['mark_rate_products'] = 100 * $marginInfos['margin_on_products'] / $marginInfos['pv_products']; + + if ($marginInfos['pa_services'] > 0) + $marginInfos['margin_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pa_services']; + if ($marginInfos['pv_services'] > 0) + $marginInfos['mark_rate_services'] = 100 * $marginInfos['margin_on_services'] / $marginInfos['pv_services']; + + // if credit note, margin = -1 * (abs(selling_price) - buying_price) + if ($marginInfos['pv_total'] < 0) + $marginInfos['total_margin'] = -1 * (abs($marginInfos['pv_total']) - $marginInfos['pa_total']); + else + $marginInfos['total_margin'] = $marginInfos['pv_total'] - $marginInfos['pa_total']; + if ($marginInfos['pa_total'] > 0) + $marginInfos['total_margin_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pa_total']; + if ($marginInfos['pv_total'] > 0) + $marginInfos['total_mark_rate'] = 100 * $marginInfos['total_margin'] / $marginInfos['pv_total']; + + return $marginInfos; + } + + /** + * Show the array with all margin infos + * + * @param CommonObject $object Object we want to get margin information for + * @param boolean $force_price Force price + * @return void + */ + function displayMarginInfos($object, $force_price=false) + { + global $langs, $conf, $user; + + if (! empty($user->societe_id)) return; + + if (! $user->rights->margins->liretous) return; + + $rounding = min($conf->global->MAIN_MAX_DECIMALS_UNIT, $conf->global->MAIN_MAX_DECIMALS_TOT); + + $marginInfo = $this->getMarginInfosArray($object, $force_price); + + if (! empty($conf->global->MARGIN_ADD_SHOWHIDE_BUTTON)) // TODO Warning this feature rely on an external js file that may be removed. Using native js function document.cookie should be better + { + print $langs->trans('ShowMarginInfos').' : '; + $hidemargininfos = $_COOKIE['DOLUSER_MARGININFO_HIDE_SHOW']; + print ''.img_picto($langs->trans("Disabled"),'switch_off').''; + print ''.img_picto($langs->trans("Enabled"),'switch_on').''; + + print ''; + if (!empty($hidemargininfos)) print ''; + } + + print ''; + print ''; + print ''; + print ''; + if ($conf->global->MARGIN_TYPE == "1") + print ''; + else + print ''; + print ''; + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + print ''; + if (! empty($conf->global->DISPLAY_MARK_RATES)) + print ''; + print ''; + + if (! empty($conf->product->enabled)) + { + //if ($marginInfo['margin_on_products'] != 0 && $marginInfo['margin_on_services'] != 0) { + print ''; + print ''; + print ''; + print ''; + print ''; + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + print ''; + if (! empty($conf->global->DISPLAY_MARK_RATES)) + print ''; + print ''; + } + + if (! empty($conf->service->enabled)) + { + print ''; + print ''; + print ''; + print ''; + print ''; + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + print ''; + if (! empty($conf->global->DISPLAY_MARK_RATES)) + print ''; + print ''; + } + + if (! empty($conf->product->enabled) && ! empty($conf->service->enabled)) + { + print ''; + print ''; + print ''; + print ''; + print ''; + if (! empty($conf->global->DISPLAY_MARGIN_RATES)) + print ''; + if (! empty($conf->global->DISPLAY_MARK_RATES)) + print ''; + print ''; + } + print '
    '.$langs->trans('Margins').''.$langs->trans('SellingPrice').''.$langs->trans('BuyingPrice').''.$langs->trans('CostPrice').''.$langs->trans('Margin').''.$langs->trans('MarginRate').''.$langs->trans('MarkRate').'
    '.$langs->trans('MarginOnProducts').''.price($marginInfo['pv_products'], null, null, null, null, $rounding).''.price($marginInfo['pa_products'], null, null, null, null, $rounding).''.price($marginInfo['margin_on_products'], null, null, null, null, $rounding).''.(($marginInfo['margin_rate_products'] == '')?'':price($marginInfo['margin_rate_products'], null, null, null, null, $rounding).'%').''.(($marginInfo['mark_rate_products'] == '')?'':price($marginInfo['mark_rate_products'], null, null, null, null, $rounding).'%').'
    '.$langs->trans('MarginOnServices').''.price($marginInfo['pv_services'], null, null, null, null, $rounding).''.price($marginInfo['pa_services'], null, null, null, null, $rounding).''.price($marginInfo['margin_on_services'], null, null, null, null, $rounding).''.(($marginInfo['margin_rate_services'] == '')?'':price($marginInfo['margin_rate_services'], null, null, null, null, $rounding).'%').''.(($marginInfo['mark_rate_services'] == '')?'':price($marginInfo['mark_rate_services'], null, null, null, null, $rounding).'%').'
    '.$langs->trans('TotalMargin').''.price($marginInfo['pv_total'], null, null, null, null, $rounding).''.price($marginInfo['pa_total'], null, null, null, null, $rounding).''.price($marginInfo['total_margin'], null, null, null, null, $rounding).''.(($marginInfo['total_margin_rate'] == '')?'':price($marginInfo['total_margin_rate'], null, null, null, null, $rounding).'%').''.(($marginInfo['total_mark_rate'] == '')?'':price($marginInfo['total_mark_rate'], null, null, null, null, $rounding).'%').'
    '; + } + +} + diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 08c19463d27..4f286d26eb7 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -592,6 +592,7 @@ class FormOther * @param array $arrayofcolors Array of colors. Example: array('29527A','5229A3','A32929','7A367A','B1365F','0D7813') * @return void * @deprecated + * @see selectColor() */ function select_color($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='') { @@ -599,7 +600,7 @@ class FormOther } /** - * Output a HTML code to select a color + * Output a HTML code to select a color. Field will return an hexa color like '334455'. * * @param string $set_color Pre-selected color * @param string $prefix Name of HTML field @@ -611,6 +612,11 @@ class FormOther */ function selectColor($set_color='', $prefix='f_color', $form_name='', $showcolorbox=1, $arrayofcolors='', $morecss='') { + // Deprecation warning + if ($form_name) { + dol_syslog(__METHOD__ . ": form_name parameter is deprecated", LOG_WARNING); + } + global $langs,$conf; $out=''; diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index 9469b680631..6411c76eeab 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -53,9 +53,10 @@ class FormProjets * @param int $show_empty Add an empty line * @param int $discard_closed Discard closed projects (0=Keep,1=hide completely,2=Disable) * @param int $forcefocus Force focus on field (works with javascript only) + * @param int $disabled Disabled * @return int Nber of project if OK, <0 if KO */ - function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0) + function select_projects($socid=-1, $selected='', $htmlname='projectid', $maxlength=24, $option_only=0, $show_empty=1, $discard_closed=0, $forcefocus=0, $disabled=0) { global $user,$conf,$langs; @@ -82,7 +83,7 @@ class FormProjets if ($socid > 0) $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)"; $sql.= " ORDER BY p.ref ASC"; - dol_syslog(get_class($this)."::select_projects", LOG_DEBUG); + dol_syslog(__METHOD__, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -100,7 +101,7 @@ class FormProjets } if (empty($option_only)) { - $out.= ''; } if (!empty($show_empty)) { $out.= ''; @@ -147,13 +148,15 @@ class FormProjets $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); } - if (!empty($selected) && $selected == $obj->rowid && $obj->fk_statut > 0) + if (!empty($selected) && $selected == $obj->rowid) { - $out.= ''; + $out.= '