1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822 |
- <?php
- /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
- * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
- * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
- * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
- * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
- * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.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
- * 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 <http://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/compta/facture/fiche-rec.php
- * \ingroup facture
- * \brief Page to show predefined invoice
- */
- require '../../main.inc.php';
- require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
- require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
- require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
- $langs->load('bills');
- $langs->load('compta');
- // Security check
- $id=(GETPOST('facid','int')?GETPOST('facid','int'):GETPOST('id','int'));
- $confirm = GETPOST('confirm', 'alpha');
- $cancel = GETPOST('cancel', 'alpha');
- $lineid=GETPOST('lineid','int');
- $ref=GETPOST('ref','alpha');
- $action=GETPOST('action', 'alpha');
- if ($user->societe_id) $socid=$user->societe_id;
- $objecttype = 'facture_rec';
- if ($action == "create" || $action == "add") $objecttype = '';
- $result = restrictedArea($user, 'facture', $id, $objecttype);
- $projectid = GETPOST('projectid','int');
- $search_ref=GETPOST('search_ref');
- $search_societe=GETPOST('search_societe');
- $search_montant_ht=GETPOST('search_montant_ht');
- $search_montant_vat=GETPOST('search_montant_vat');
- $search_montant_ttc=GETPOST('search_montant_ttc');
- $day=GETPOST('day');
- $year=GETPOST('year');
- $month=GETPOST('month');
- $day_date_when=GETPOST('day_date_when');
- $year_date_when=GETPOST('year_date_when');
- $month_date_when=GETPOST('month_date_when');
- $search_frequency=GETPOST('search_frequency');
- $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
- $sortfield = GETPOST("sortfield",'alpha');
- $sortorder = GETPOST("sortorder",'alpha');
- $page = GETPOST("page",'int');
- if ($page == -1) { $page = 0; }
- $offset = $limit * $page;
- if (! $sortorder) $sortorder='DESC';
- if (! $sortfield) $sortfield='f.titre';
- $pageprev = $page - 1;
- $pagenext = $page + 1;
- $object = new FactureRec($db);
- if (($id > 0 || $ref) && $action != 'create' && $action != 'add')
- {
- $ret = $object->fetch($id, $ref);
- if (!$ret)
- {
- setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
- }
- }
- // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
- $hookmanager->initHooks(array('invoicecard','globalcard'));
- $extrafields = new ExtraFields($db);
- // fetch optionals attributes and labels
- $extralabels = $extrafields->fetch_name_optionals_label('facturerec');
- $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
- $permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php
- $permissiondellink=$user->rights->facture->creer; // Used by the include of actions_dellink.inc.php
- $permissiontoedit = $user->rights->facture->creer; // Used by the include of actions_lineupdonw.inc.php
- $arrayfields=array(
- 'f.titre'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
- 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
- 'f.total'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1),
- 'f.tva'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>1),
- 'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>1),
- 'f.frequency'=>array('label'=>$langs->trans("RecurringInvoiceTemplate"), 'checked'=>1),
- 'f.date_last_gen'=>array('label'=>$langs->trans("DateLastGeneration"), 'checked'=>1),
- 'f.date_when'=>array('label'=>$langs->trans("NextDateToExecution"), 'checked'=>1),
- 'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
- 'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
- );
- // Extra fields
- if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
- {
- foreach($extrafields->attribute_label as $key => $val)
- {
- $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
- }
- }
- /*
- * Actions
- */
- // Set note
- include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
- include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
- // Create predefined invoice
- if ($action == 'add')
- {
- if (! GETPOST('titre'))
- {
- setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("Title")), null, 'errors');
- $action = "create";
- $error++;
- }
- $frequency=GETPOST('frequency', 'int');
- $reyear=GETPOST('reyear');
- $remonth=GETPOST('remonth');
- $reday=GETPOST('reday');
- $rehour=GETPOST('rehour');
- $remin=GETPOST('remin');
- $nb_gen_max=GETPOST('nb_gen_max', 'int');
- //if (empty($nb_gen_max)) $nb_gen_max =0;
-
- if (GETPOST('frequency'))
- {
- if (empty($reyear) || empty($remonth) || empty($reday))
- {
- setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("Date")), null, 'errors');
- $action = "create";
- $error++;
- }
- if ($nb_gen_max === '')
- {
- setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("MaxPeriodNumber")), null, 'errors');
- $action = "create";
- $error++;
- }
- }
- if (! $error)
- {
- $object->titre = GETPOST('titre', 'alpha');
- $object->note_private = GETPOST('note_private');
- $object->note_public = GETPOST('note_public');
- $object->usenewprice = GETPOST('usenewprice');
-
- $object->frequency = $frequency;
- $object->unit_frequency = GETPOST('unit_frequency', 'alpha');
- $object->nb_gen_max = $nb_gen_max;
- $object->auto_validate = GETPOST('auto_validate', 'int');
-
- $object->fk_project = $projectid;
-
- $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
- $object->date_when = $date_next_execution;
- // Get first contract linked to invoice used to generate template
- if ($id > 0)
- {
- $srcObject = new Facture($db);
- $srcObject->fetch(GETPOST('facid','int'));
-
- $srcObject->fetchObjectLinked();
-
- if (! empty($srcObject->linkedObjectsIds['contrat']))
- {
- $contractidid = reset($srcObject->linkedObjectsIds['contrat']);
- $object->origin = 'contrat';
- $object->origin_id = $contractidid;
- $object->linked_objects[$object->origin] = $object->origin_id;
- }
- }
-
- $db->begin();
- $oldinvoice = new Facture($db);
- $oldinvoice->fetch($id);
-
- $result = $object->create($user, $oldinvoice->id);
- if ($result > 0)
- {
- $result=$oldinvoice->delete(0, 1);
- if ($result < 0)
- {
- $error++;
- setEventMessages($oldinvoice->error, $oldinvoice->errors, 'errors');
- $action = "create";
- }
- }
- else
- {
- $error++;
- setEventMessages($object->error, $object->errors, 'errors');
- $action = "create";
- }
-
- if (! $error)
- {
- $db->commit();
-
- header("Location: " . $_SERVER['PHP_SELF'] . '?facid=' . $object->id);
- exit;
- }
- else
- {
- $db->rollback();
-
- $error++;
- setEventMessages($object->error, $object->errors, 'errors');
- $action = "create";
- }
- }
- }
- // Delete
- if ($action == 'delete' && $user->rights->facture->supprimer)
- {
- $object->delete();
- header("Location: " . $_SERVER['PHP_SELF'] );
- exit;
- }
- // Update field
- // Set condition
- if ($action == 'setconditions' && $user->rights->facture->creer)
- {
- $result=$object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
- }
- // Set mode
- elseif ($action == 'setmode' && $user->rights->facture->creer)
- {
- $result=$object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
- }
- // Set project
- elseif ($action == 'classin' && $user->rights->facture->creer)
- {
- $object->setProject(GETPOST('projectid', 'int'));
- }
- // Set bank account
- elseif ($action == 'setbankaccount' && $user->rights->facture->creer)
- {
- $result=$object->setBankAccount(GETPOST('fk_account', 'int'));
- }
- // Set frequency and unit frequency
- elseif ($action == 'setfrequency' && $user->rights->facture->creer)
- {
- $object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha'));
- }
- // Set next date of execution
- elseif ($action == 'setdate_when' && $user->rights->facture->creer)
- {
- $date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear'));
- if (!empty($date)) $object->setNextDate($date);
- }
- // Set max period
- elseif ($action == 'setnb_gen_max' && $user->rights->facture->creer)
- {
- $object->setMaxPeriod(GETPOST('nb_gen_max', 'int'));
- }
- // Set auto validate
- elseif ($action == 'setauto_validate' && $user->rights->facture->creer)
- {
- $object->setAutoValidate(GETPOST('auto_validate', 'int'));
- }
- // Delete line
- if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer)
- {
- $object->fetch($id);
- $object->fetch_thirdparty();
- $db->begin();
-
- $line=new FactureLigneRec($db);
-
- // For triggers
- $line->id = $lineid;
-
- if ($line->delete() > 0)
- {
- $result=$object->update_price(1);
-
- if ($result > 0)
- {
- $db->commit();
- $object->fetch($object->id); // Reload lines
- }
- else
- {
- $db->rollback();
- setEventMessages($db->lasterror(), null, 'errors');
- }
- }
- else
- {
- $db->rollback();
- setEventMessages($line->error, $line->errors, 'errors');
- }
- }
- // Add a new line
- if ($action == 'addline' && $user->rights->facture->creer)
- {
- $langs->load('errors');
- $error = 0;
- // Set if we used free entry or predefined product
- $predef='';
- $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):'');
- $price_ht = GETPOST('price_ht');
- if (GETPOST('prod_entry_mode') == 'free')
- {
- $idprod=0;
- $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
- }
- else
- {
- $idprod=GETPOST('idprod', 'int');
- $tva_tx = '';
- }
- $qty = GETPOST('qty' . $predef);
- $remise_percent = GETPOST('remise_percent' . $predef);
- // Extrafields
- $extrafieldsline = new ExtraFields($db);
- $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
- $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef);
- // Unset extrafield
- if (is_array($extralabelsline)) {
- // Get extra fields
- foreach ($extralabelsline as $key => $value) {
- unset($_POST["options_" . $key . $predef]);
- }
- }
- if (empty($idprod) && ($price_ht < 0) && ($qty < 0)) {
- setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
- $error ++;
- }
- if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && GETPOST('type') < 0) {
- setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors');
- $error ++;
- }
- if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && (! ($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not ''
- {
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
- $error ++;
- }
- if ($qty == '') {
- setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
- $error ++;
- }
- if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && empty($product_desc)) {
- setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
- $error ++;
- }
- if ($qty < 0) {
- $langs->load("errors");
- setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors');
- $error ++;
- }
-
- if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod))) {
- $ret = $object->fetch($id);
- if ($ret < 0) {
- dol_print_error($db, $object->error);
- exit();
- }
- $ret = $object->fetch_thirdparty();
- // Clean parameters
- $date_start = dol_mktime(GETPOST('date_start' . $predef . 'hour'), GETPOST('date_start' . $predef . 'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year'));
- $date_end = dol_mktime(GETPOST('date_end' . $predef . 'hour'), GETPOST('date_end' . $predef . 'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year'));
- $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
- // Define special_code for special lines
- $special_code = 0;
- // if (empty($_POST['qty'])) $special_code=3; // Options should not exists on invoices
- // Ecrase $pu par celui du produit
- // Ecrase $desc par celui du produit
- // Ecrase $txtva par celui du produit
- // Ecrase $base_price_type par celui du produit
- // Replaces $fk_unit with the product's
- if (! empty($idprod))
- {
- $prod = new Product($db);
- $prod->fetch($idprod);
- $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
- // Update if prices fields are defined
- $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
- $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
- if (empty($tva_tx)) $tva_npr=0;
-
- $pu_ht = $prod->price;
- $pu_ttc = $prod->price_ttc;
- $price_min = $prod->price_min;
- $price_base_type = $prod->price_base_type;
- // We define price for product
- if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level))
- {
- $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
- $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
- $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
- $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
- if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility
- {
- if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) $tva_tx=$prod->multiprices_tva_tx[$object->thirdparty->price_level];
- if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$object->thirdparty->price_level];
- if (empty($tva_tx)) $tva_npr=0;
- }
- }
- elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES))
- {
- require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
- $prodcustprice = new Productcustomerprice($db);
- $filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $object->thirdparty->id);
- $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
- if ($result) {
- if (count($prodcustprice->lines) > 0) {
- $pu_ht = price($prodcustprice->lines[0]->price);
- $pu_ttc = price($prodcustprice->lines[0]->price_ttc);
- $price_base_type = $prodcustprice->lines[0]->price_base_type;
- $prod->tva_tx = $prodcustprice->lines[0]->tva_tx;
- }
- }
- }
- // if price ht was forced (ie: from gui when calculated by margin rate and cost price)
- if (! empty($price_ht))
- {
- $pu_ht = price2num($price_ht, 'MU');
- $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU');
- }
- // On reevalue prix selon taux tva car taux tva transaction peut etre different
- // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
- elseif ($tva_tx != $prod->tva_tx)
- {
- if ($price_base_type != 'HT')
- {
- $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU');
- }
- else
- {
- $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU');
- }
- }
- $desc = '';
- // Define output language
- if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
- $outputlangs = $langs;
- $newlang = '';
- if (empty($newlang) && GETPOST('lang_id'))
- $newlang = GETPOST('lang_id');
- if (empty($newlang))
- $newlang = $object->thirdparty->default_lang;
- if (! empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $desc = (! empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description;
- } else {
- $desc = $prod->description;
- }
- $desc = dol_concatdesc($desc, $product_desc);
- // Add custom code and origin country into description
- if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (! empty($prod->customcode) || ! empty($prod->country_code))) {
- $tmptxt = '(';
- if (! empty($prod->customcode))
- $tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
- if (! empty($prod->customcode) && ! empty($prod->country_code))
- $tmptxt .= ' - ';
- if (! empty($prod->country_code))
- $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
- $tmptxt .= ')';
- $desc = dol_concatdesc($desc, $tmptxt);
- }
- $type = $prod->type;
- $fk_unit = $prod->fk_unit;
- } else {
- $pu_ht = price2num($price_ht, 'MU');
- $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
- $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
- $tva_tx = str_replace('*', '', $tva_tx);
- if (empty($tva_tx)) $tva_npr=0;
- $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
- $desc = $product_desc;
- $type = GETPOST('type');
- $fk_unit= GETPOST('units', 'alpha');
- }
-
- // Margin
- $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
- $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we must keep this value
- // Local Taxes
- $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
- $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
-
- $info_bits = 0;
- if ($tva_npr)
- $info_bits |= 0x01;
- if (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min))) {
- $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency));
- setEventMessages($mesg, null, 'errors');
- } else {
- // Insert line
- $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, - 1, $special_code, $label, $fk_unit);
- if ($result > 0)
- {
- /*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
- {
- // Define output language
- $outputlangs = $langs;
- $newlang = '';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang;
- if (! empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $model=$object->modelpdf;
- $ret = $object->fetch($id); // Reload to get new records
- $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
- if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
- }*/
- $object->fetch($object->id); // Reload lines
-
- unset($_POST['prod_entry_mode']);
- unset($_POST['qty']);
- unset($_POST['type']);
- unset($_POST['remise_percent']);
- unset($_POST['price_ht']);
- unset($_POST['multicurrency_price_ht']);
- unset($_POST['price_ttc']);
- unset($_POST['tva_tx']);
- unset($_POST['product_ref']);
- unset($_POST['product_label']);
- unset($_POST['product_desc']);
- unset($_POST['fournprice']);
- unset($_POST['buying_price']);
- unset($_POST['np_marginRate']);
- unset($_POST['np_markRate']);
- unset($_POST['dp_desc']);
- unset($_POST['idprod']);
- unset($_POST['units']);
- unset($_POST['date_starthour']);
- unset($_POST['date_startmin']);
- unset($_POST['date_startsec']);
- unset($_POST['date_startday']);
- unset($_POST['date_startmonth']);
- unset($_POST['date_startyear']);
- unset($_POST['date_endhour']);
- unset($_POST['date_endmin']);
- unset($_POST['date_endsec']);
- unset($_POST['date_endday']);
- unset($_POST['date_endmonth']);
- unset($_POST['date_endyear']);
- unset($_POST['situations']);
- unset($_POST['progress']);
- } else {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- $action = '';
- }
- }
- }
- elseif ($action == 'updateligne' && $user->rights->facture->creer && ! GETPOST('cancel'))
- {
- if (! $object->fetch($id) > 0) dol_print_error($db);
- $object->fetch_thirdparty();
- // Clean parameters
- $date_start = '';
- $date_end = '';
- //$date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
- //$date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
- $description = dol_htmlcleanlastbr(GETPOST('product_desc') ? GETPOST('product_desc') : GETPOST('desc'));
- $pu_ht = GETPOST('price_ht');
- $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
- $qty = GETPOST('qty');
- // Define info_bits
- $info_bits = 0;
- if (preg_match('/\*/', $vat_rate))
- $info_bits |= 0x01;
- // Define vat_rate
- $vat_rate = str_replace('*', '', $vat_rate);
- $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty);
- $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty);
- // Add buying price
- $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : '');
- $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value
- // Extrafields
- $extrafieldsline = new ExtraFields($db);
- $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line);
- $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline);
- // Unset extrafield
- if (is_array($extralabelsline)) {
- // Get extra fields
- foreach ($extralabelsline as $key => $value) {
- unset($_POST["options_" . $key]);
- }
- }
- // Define special_code for special lines
- $special_code=GETPOST('special_code');
- if (! GETPOST('qty')) $special_code=3;
- /*$line = new FactureLigne($db);
- $line->fetch(GETPOST('lineid'));
- $percent = $line->get_prev_progress($object->id);
- if (GETPOST('progress') < $percent)
- {
- $mesg = '<div class="warning">' . $langs->trans("CantBeLessThanMinPercent") . '</div>';
- setEventMessages($mesg, null, 'warnings');
- $error++;
- $result = -1;
- }*/
- // Check minimum price
- $productid = GETPOST('productid', 'int');
- if (! empty($productid))
- {
- $product = new Product($db);
- $product->fetch($productid);
- $type = $product->type;
- $price_min = $product->price_min;
- if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($object->thirdparty->price_level))
- $price_min = $product->multiprices_min [$object->thirdparty->price_level];
- $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
- // Check price is not lower than minimum (check is done only for standard or replacement invoices)
- if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min))) {
- setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors');
- $error ++;
- }
- } else {
- $type = GETPOST('type');
- $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
- // Check parameters
- if (GETPOST('type') < 0) {
- setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
- $error ++;
- }
- }
- if ($qty < 0) {
- $langs->load("errors");
- setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors');
- $error ++;
- }
- // Update line
- if (! $error) {
- $result = $object->updateline(GETPOST('lineid'), $description, $pu_ht, $qty,
- $vat_rate, GETPOST('productid'), GETPOST('remise_percent'), 'HT', $info_bits, 0, 0, $type,
- 0, $special_code, $label, GETPOST('units'));
- if ($result >= 0) {
- /*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
- // Define output language
- $outputlangs = $langs;
- $newlang = '';
- if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id'))
- $newlang = GETPOST('lang_id');
- if ($conf->global->MAIN_MULTILANGS && empty($newlang))
- $newlang = $object->thirdparty->default_lang;
- if (! empty($newlang)) {
- $outputlangs = new Translate("", $conf);
- $outputlangs->setDefaultLang($newlang);
- }
- $ret = $object->fetch($id); // Reload to get new records
- $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
- }*/
- $object->fetch($object->id); // Reload lines
-
- unset($_POST['qty']);
- unset($_POST['type']);
- unset($_POST['productid']);
- unset($_POST['remise_percent']);
- unset($_POST['price_ht']);
- unset($_POST['multicurrency_price_ht']);
- unset($_POST['price_ttc']);
- unset($_POST['tva_tx']);
- unset($_POST['product_ref']);
- unset($_POST['product_label']);
- unset($_POST['product_desc']);
- unset($_POST['fournprice']);
- unset($_POST['buying_price']);
- unset($_POST['np_marginRate']);
- unset($_POST['np_markRate']);
- unset($_POST['dp_desc']);
- unset($_POST['idprod']);
- unset($_POST['units']);
- unset($_POST['date_starthour']);
- unset($_POST['date_startmin']);
- unset($_POST['date_startsec']);
- unset($_POST['date_startday']);
- unset($_POST['date_startmonth']);
- unset($_POST['date_startyear']);
- unset($_POST['date_endhour']);
- unset($_POST['date_endmin']);
- unset($_POST['date_endsec']);
- unset($_POST['date_endday']);
- unset($_POST['date_endmonth']);
- unset($_POST['date_endyear']);
- unset($_POST['situations']);
- unset($_POST['progress']);
- } else {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- }
- // Do we click on purge search criteria ?
- if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
- {
- $search_ref='';
- $search_societe='';
- $search_montant_ht='';
- $search_montant_vat='';
- $search_montant_ttc='';
- $day='';
- $year='';
- $month='';
- $day_date_when='';
- $year_date_when='';
- $month_date_when='';
- $search_frequency='';
- $search_array_options=array();
- }
- /*
- * View
- */
- llxHeader('',$langs->trans("RepeatableInvoices"),'ch-facture.html#s-fac-facture-rec');
- $form = new Form($db);
- $formother = new FormOther($db);
- $companystatic = new Societe($db);
- $now = dol_now();
- $tmparray=dol_getdate($now);
- $today = dol_mktime(23,59,59,$tmparray['mon'],$tmparray['mday'],$tmparray['year']); // Today is last second of current day
-
- /*
- * Create mode
- */
- if ($action == 'create')
- {
- print load_fiche_titre($langs->trans("CreateRepeatableInvoice"),'','title_accountancy.png');
- $object = new Facture($db); // Source invoice
- $product_static = new Product($db);
- $formproject = new FormProjets($db);
-
- if ($object->fetch($id, $ref) > 0)
- {
- $result = $object->getLinesArray();
-
- print '<form action="fiche-rec.php" method="post">';
- print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
- print '<input type="hidden" name="action" value="add">';
- print '<input type="hidden" name="facid" value="'.$object->id.'">';
- dol_fiche_head();
- $rowspan=4;
- if (! empty($conf->projet->enabled)) $rowspan++;
- if ($object->fk_account > 0) $rowspan++;
- print '<table class="border" width="100%">';
- $object->fetch_thirdparty();
- // Third party
- print '<tr><td class="titlefieldcreate">'.$langs->trans("Customer").'</td><td>'.$object->thirdparty->getNomUrl(1,'customer').'</td>';
- print '</tr>';
- // Title
- print '<tr><td class="fieldrequired">'.$langs->trans("Title").'</td><td>';
- print '<input class="flat quatrevingtpercent" type="text" name="titre" value="'.$_POST["titre"].'">';
- print '</td></tr>';
- // Note public
- print '<tr><td>'.$langs->trans("NotePublic").'</td><td valign="top">';
- print '<textarea class="flat centpercent" name="note_public" wrap="soft" rows="'.ROWS_4.'"></textarea>';
- print '</td></tr>';
- // Note private
- print '<tr><td>'.$langs->trans("NotePrivate").'</td><td valign="top">';
- print '<textarea class="flat centpercent" name="note_private" wrap="soft" rows="'.ROWS_4.'"></textarea>';
- print '</td></tr>';
-
- // Author
- print "<tr><td>".$langs->trans("Author")."</td><td>".$user->getFullName($langs)."</td></tr>";
- // Payment term
- print "<tr><td>".$langs->trans("PaymentConditions")."</td><td>";
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none');
- print "</td></tr>";
- // Payment mode
- print "<tr><td>".$langs->trans("PaymentMode")."</td><td>";
- $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
- print "</td></tr>";
- // Project
- if (! empty($conf->projet->enabled) && is_object($object->thirdparty) && $object->thirdparty->id > 0)
- {
- $projectid = $object->fk_project;
- $langs->load('projects');
- print '<tr><td>' . $langs->trans('Project') . '</td><td>';
- $numprojet = $formproject->select_projects($socid, $projectid, 'projectid', 0);
- print ' <a href="'.DOL_URL_ROOT.'/projet/card.php?socid=' . $soc->id . '&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id).'">' . $langs->trans("AddProject") . '</a>';
- print '</td></tr>';
- }
-
- // Bank account
- if ($object->fk_account > 0)
- {
- print "<tr><td>".$langs->trans('BankAccount')."</td><td>";
- $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
- print "</td></tr>";
- }
- print "</table>";
- print '<br><br>';
-
- // Autogeneration
- $title = $langs->trans("Recurrence");
- print load_fiche_titre($title, '', 'calendar');
-
- print '<table class="border" width="100%">';
-
- // Frequency
- print '<tr><td class="titlefieldcreate">'.$form->textwithpicto($langs->trans("Frequency"), $langs->transnoentitiesnoconv('toolTipFrequency'))."</td><td>";
- print "<input type='text' name='frequency' value='".GETPOST('frequency', 'int')."' size='5' /> ".$form->selectarray('unit_frequency', array('d'=>$langs->trans('Day'), 'm'=>$langs->trans('Month'), 'y'=>$langs->trans('Year')), (GETPOST('unit_frequency')?GETPOST('unit_frequency'):'m'));
- print "</td></tr>";
-
- // First date of execution for cron
- print "<tr><td>".$langs->trans('NextDateToExecution')."</td><td>";
- $date_next_execution = isset($date_next_execution) ? $date_next_execution : (GETPOST('remonth') ? dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')) : -1);
- print $form->select_date($date_next_execution, '', 1, 1, '', "add", 1, 1, 1);
- print "</td></tr>";
-
- // Number max of generation
- print "<tr><td>".$langs->trans("MaxPeriodNumber")."</td><td>";
- print '<input type="text" name="nb_gen_max" value="'.GETPOST('nb_gen_max').'" size="5" />';
- print "</td></tr>";
- // Auto validate the invoice
- print "<tr><td>".$langs->trans("StatusOfGeneratedInvoices")."</td><td>";
- $select = array('0'=>$langs->trans('BillStatusDraft'),'1'=>$langs->trans('BillStatusValidated'));
- print $form->selectarray('auto_validate', $select, GETPOST('auto_validate'));
- print "</td></tr>";
- print "</table>";
- print '<br><br>';
- $title = $langs->trans("ProductsAndServices");
- if (empty($conf->service->enabled))
- $title = $langs->trans("Products");
- else if (empty($conf->product->enabled))
- $title = $langs->trans("Services");
- print load_fiche_titre($title, '', '');
- /*
- * Invoice lines
- */
- print '<table id="tablelines" class="noborder noshadow" width="100%">';
- // Show object lines
- if (! empty($object->lines))
- {
- $disableedit=1;
- $disablemove=1;
- $disableremove=1;
- $ret = $object->printObjectLines('', $mysoc, $soc, $lineid, 0); // No date selector for template invoice
- }
-
- print "</table>\n";
-
- /*
- print '<table class="notopnoleftnoright" width="100%">';
- print '<tr><td colspan="3">';
- $sql = 'SELECT l.fk_product, l.product_type, l.label as custom_label, l.description, l.qty, l.rowid, l.tva_tx,';
- $sql.= ' l.fk_remise_except,';
- $sql.= ' l.remise_percent, l.subprice, l.info_bits,';
- $sql.= ' l.total_ht, l.total_tva as total_vat, l.total_ttc,';
- $sql.= ' l.date_start,';
- $sql.= ' l.date_end,';
- $sql.= ' l.product_type,';
- $sql.= ' l.fk_unit,';
- $sql.= ' p.ref, p.fk_product_type, p.label as product_label,';
- $sql.= ' p.description as product_desc';
- $sql.= " FROM ".MAIN_DB_PREFIX."facturedet as l";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product = p.rowid";
- $sql.= " WHERE l.fk_facture = ".$object->id;
- $sql.= " ORDER BY l.rowid";
- $result = $db->query($sql);
- if ($result)
- {
- $num = $db->num_rows($result);
- $i = 0; $total = 0;
- echo '<table class="noborder" width="100%">';
- if ($num)
- {
- print '<tr class="liste_titre">';
- print '<td>'.$langs->trans("Description").'</td>';
- print '<td align="center">'.$langs->trans("VAT").'</td>';
- print '<td align="center">'.$langs->trans("Qty").'</td>';
- if ($conf->global->PRODUCT_USE_UNITS) {
- print '<td width="8%" align="left">'.$langs->trans("Unit").'</td>';
- }
- print '<td>'.$langs->trans("ReductionShort").'</td>';
- print '<td align="right">'.$langs->trans("TotalHT").'</td>';
- print '<td align="right">'.$langs->trans("TotalVAT").'</td>';
- print '<td align="right">'.$langs->trans("TotalTTC").'</td>';
- print '<td align="right">'.$langs->trans("PriceUHT").'</td>';
- if (empty($conf->global->PRODUIT_MULTIPRICES)) print '<td align="right">'.$langs->trans("CurrentProductPrice").'</td>';
- print "</tr>\n";
- }
- $var=true;
- while ($i < $num)
- {
- $objp = $db->fetch_object($result);
- if ($objp->fk_product > 0)
- {
- $product = New Product($db);
- $product->fetch($objp->fk_product);
- }
- $var=!$var;
- print "<tr ".$bc[$var].">";
- // Show product and description
- $type=(isset($objp->product_type)?$objp->product_type:$objp->fk_product_type);
- $product_static->fk_unit=$objp->fk_unit;
- if ($objp->fk_product > 0)
- {
- print '<td>';
- print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
- // Show product and description
- $product_static->fetch($objp->fk_product); // We need all information later
- $text=$product_static->getNomUrl(1);
- $text.= ' - '.(! empty($objp->custom_label)?$objp->custom_label:$objp->product_label);
- $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($objp->description));
- print $form->textwithtooltip($text,$description,3,'','',$i);
- // Show range
- print_date_range($db->jdate($objp->date_start), $db->jdate($objp->date_end));
- // Add description in form
- if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
- print (! empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):'';
- print '</td>';
- }
- else
- {
- print '<td>';
- print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
- if ($type==1) $text = img_object($langs->trans('Service'),'service');
- else $text = img_object($langs->trans('Product'),'product');
- if (! empty($objp->custom_label)) {
- $text.= ' <strong>'.$objp->custom_label.'</strong>';
- print $form->textwithtooltip($text,dol_htmlentitiesbr($objp->description),3,'','',$i);
- } else {
- print $text.' '.nl2br($objp->description);
- }
- // Show range
- print_date_range($db->jdate($objp->date_start), $db->jdate($objp->date_end));
- print "</td>\n";
- }
- // Vat rate
- print '<td align="center">'.vatrate($objp->tva_tx).'%</td>';
- // Qty
- print '<td align="center">'.$objp->qty.'</td>';
- if ($conf->global->PRODUCT_USE_UNITS) {
- print '<td align="left">'.$product_static->getLabelOfUnit().'</td>';
- }
- // Percent
- if ($objp->remise_percent > 0)
- {
- print '<td align="right">'.$objp->remise_percent." %</td>\n";
- }
- else
- {
- print '<td> </td>';
- }
- // Total HT
- print '<td align="right">'.price($objp->total_ht)."</td>\n";
- // Total VAT
- print '<td align="right">'.price($objp->total_vat)."</td>\n";
- // Total TTC
- print '<td align="right">'.price($objp->total_ttc)."</td>\n";
- // Total Unit price
- print '<td align="right">'.price($objp->subprice)."</td>\n";
- // Current price of product
- if (empty($conf->global->PRODUIT_MULTIPRICES))
- {
- if ($objp->fk_product > 0)
- {
- $flag_price_may_change++;
- $prodprice=$product_static->price; // price HT
- print '<td align="right">'.price($prodprice)."</td>\n";
- }
- else
- {
- print '<td> </td>';
- }
- }
- print "</tr>";
- $i++;
- }
- $db->free($result);
- }
- else
- {
- print $db->error();
- }
- print "</table>";
- */
-
- print '</td></tr>';
- if ($flag_price_may_change)
- {
- print '<tr><td colspan="3" align="left">';
- print '<select name="usenewprice" class="flat">';
- print '<option value="0">'.$langs->trans("AlwaysUseFixedPrice").'</option>';
- print '<option value="1" disabled>'.$langs->trans("AlwaysUseNewPrice").'</option>';
- print '</select>';
- print '</td></tr>';
- }
- print "</table>\n";
- dol_fiche_end();
- print '<div align="center"><input type="submit" class="button" value="'.$langs->trans("Create").'">';
- print ' ';
- print '<input type="button" class="button" value="' . $langs->trans("Cancel") . '" onClick="javascript:history.go(-1)">';
- print '</div>';
- print "</form>\n";
- }
- else
- {
- dol_print_error('',"Error, no invoice ".$object->id);
- }
- }
- else
- {
- /*
- * View mode
- */
- if ($object->id > 0)
- {
- $object->fetch_thirdparty();
- // Confirmation de la suppression d'une ligne produit
- if ($action == 'ask_deleteline') {
- $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1);
- }
-
- print $formconfirm;
-
- $author = new User($db);
- $author->fetch($object->user_author);
-
- $head=array();
- $h=0;
- $head[$h][0] = $_SERVER["PHP_SELF"].'?id='.$object->id;
- $head[$h][1] = $langs->trans("CardBill");
- $head[$h][2] = 'card';
- dol_fiche_head($head, 'card', $langs->trans("RepeatableInvoice"),0,'bill'); // Add a div
- print '<table class="border" width="100%">';
- $linkback = '<a href="' . DOL_URL_ROOT . '/compta/facture/fiche-rec.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
- // Ref
- print '<tr><td width="20%">' . $langs->trans('Ref') . '</td>';
- print '<td colspan="5">';
- $morehtmlref = '';
- /*
- require_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php';
- $discount = new DiscountAbsolute($db);
- $result = $discount->fetch(0, $object->id);
- if ($result > 0) {
- $morehtmlref = ' (' . $langs->trans("CreditNoteConvertedIntoDiscount", $discount->getNomUrl(1, 'discount')) . ')';
- }
- if ($result < 0) {
- dol_print_error('', $discount->error);
- }*/
- print $form->showrefnav($object, 'ref', $linkback, 1, 'titre', 'titre', $morehtmlref);
- print '</td></tr>';
-
-
- print '<tr><td>'.$langs->trans("Customer").'</td>';
- print '<td colspan="3">'.$object->thirdparty->getNomUrl(1,'customer').'</td></tr>';
- print "<tr><td>".$langs->trans("Author").'</td><td colspan="3">'.$author->getFullName($langs)."</td></tr>";
- print '<tr><td>'.$langs->trans("AmountHT").'</td>';
- print '<td colspan="3">'.price($object->total_ht,'',$langs,1,-1,-1,$conf->currency).'</td>';
- print '</tr>';
- print '<tr><td>'.$langs->trans("AmountVAT").'</td><td colspan="3">'.price($object->total_tva,'',$langs,1,-1,-1,$conf->currency).'</td>';
- print '</tr>';
- print '<tr><td>'.$langs->trans("AmountTTC").'</td><td colspan="3">'.price($object->total_ttc,'',$langs,1,-1,-1,$conf->currency).'</td>';
- print '</tr>';
- // Payment term
- print '<tr><td>';
- print '<table class="nobordernopadding" width="100%"><tr><td>';
- print $langs->trans('PaymentConditionsShort');
- print '</td>';
- if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && ! empty($object->brouillon) && $user->rights->facture->creer)
- print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editconditions&facid=' . $object->id . '">' . img_edit($langs->trans('SetConditions'), 1) . '</a></td>';
- print '</tr></table>';
- print '</td><td colspan="3">';
- if ($object->type != Facture::TYPE_CREDIT_NOTE)
- {
- if ($action == 'editconditions') {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'cond_reglement_id');
- } else {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'none');
- }
- } else {
- print ' ';
- }
- print '</td></tr>';
- // Payment mode
- print '<tr><td>';
- print '<table class="nobordernopadding" width="100%"><tr><td>';
- print $langs->trans('PaymentMode');
- print '</td>';
- if ($action != 'editmode' && ! empty($object->brouillon) && $user->rights->facture->creer)
- print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editmode&facid=' . $object->id . '">' . img_edit($langs->trans('SetMode'), 1) . '</a></td>';
- print '</tr></table>';
- print '</td><td colspan="3">';
- if ($action == 'editmode')
- {
- $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT');
- }
- else
- {
- $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'none', 'CRDT');
- }
- print '</td></tr>';
- // Note public
- print '<tr><td>';
- print $form->editfieldkey($langs->trans("NotePublic"), 'note_public', $object->note_public, $object, $user->rights->facture->creer);
- print '</td><td colspan="5">';
- print $form->editfieldval($langs->trans("NotePublic"), 'note_public', $object->note_public, $object, $user->rights->facture->creer, 'textarea:'.ROWS_4.':60');
- print '</td>';
- print '</tr>';
-
- // Note private
- print '<tr><td>';
- print $form->editfieldkey($langs->trans("NotePrivate"), 'note_private', $object->note_private, $object, $user->rights->facture->creer);
- print '</td><td colspan="5">';
- print $form->editfieldval($langs->trans("NotePrivate"), 'note_private', $object->note_private, $object, $user->rights->facture->creer, 'textarea:'.ROWS_4.':60');
- print '</td>';
- print '</tr>';
-
- // Project
- if (! empty($conf->projet->enabled)) {
- $langs->load('projects');
- print '<tr>';
- print '<td>';
-
- print '<table class="nobordernopadding" width="100%"><tr><td>';
- print $langs->trans('Project');
- print '</td>';
- if ($action != 'classify') {
- print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=classify&facid=' . $object->id . '">';
- print img_edit($langs->trans('SetProject'), 1);
- print '</a></td>';
- }
- print '</tr></table>';
-
- print '</td><td colspan="3">';
- if ($action == 'classify') {
- $form->form_project($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1);
- } else {
- $form->form_project($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0);
- }
- print '</td>';
- print '</tr>';
- }
- // Bank Account
- print '<tr><td class="nowrap">';
- print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
- print $langs->trans('BankAccount');
- print '<td>';
- if (($action != 'editbankaccount') && $user->rights->commande->creer && ! empty($object->brouillon))
- print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'),1).'</a></td>';
- print '</tr></table>';
- print '</td><td colspan="3">';
- if ($action == 'editbankaccount')
- {
- $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
- }
- else
- {
- $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
- }
- print "</td>";
- print '</tr>';
- print "</table>";
- print '<br>';
- /*
- * Recurrence
- */
- $title = $langs->trans("Recurrence");
- print load_fiche_titre($title, '', 'calendar');
-
- print '<table class="border" width="100%">';
- // if "frequency" is empty or = 0, the reccurence is disabled
- print '<tr><td width="20%">';
- print '<table class="nobordernopadding" width="100%"><tr><td>';
- print $langs->trans('Frequency');
- print '</td>';
- if ($action != 'editfrequency' && ! empty($object->brouillon) && $user->rights->facture->creer)
- print '<td align="right"><a href="' . $_SERVER["PHP_SELF"] . '?action=editfrequency&facid=' . $object->id . '">' . img_edit($langs->trans('Edit'), 1) . '</a></td>';
- print '</tr></table>';
- print '</td><td colspan="5">';
- if ($action == 'editfrequency')
- {
- print '<form method="post" action="'.$_SERVER["PHP_SELF"] . '?facid=' . $object->id.'">';
- print '<input type="hidden" name="action" value="setfrequency">';
- print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
- print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
- print '<tr><td>';
- print "<input type='text' name='frequency' value='".$object->frequency."' size='5' /> ".$form->selectarray('unit_frequency', array('d'=>$langs->trans('Day'), 'm'=>$langs->trans('Month'), 'y'=>$langs->trans('Year')), ($object->unit_frequency?$object->unit_frequency:'m'));
- print '</td>';
- print '<td align="left"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
- print '</tr></table></form>';
- }
- else
- {
- if ($object->frequency > 0)
- {
- print $langs->trans('FrequencyPer_'.$object->unit_frequency, $object->frequency);
- }
- else
- {
- print $langs->trans("NotARecurringInvoiceTemplate");
- }
- }
- print '</td></tr>';
-
- // Date when
- print '<tr><td>';
- if ($action == 'date_when' || $object->frequency > 0)
- {
- print $form->editfieldkey($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day');
- }
- else
- {
- print $langs->trans("NextDateToExecution");
- }
- print '</td><td colspan="5">';
- if ($action == 'date_when' || $object->frequency > 0)
- {
- print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'day');
- }
- print '</td>';
- print '</tr>';
-
- // Max period / Rest period
- print '<tr><td>';
- if ($action == 'nb_gen_max' || $object->frequency > 0)
- {
- print $form->editfieldkey($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, $object, $user->rights->facture->creer);
- }
- else
- {
- print $langs->trans("MaxPeriodNumber");
- }
- print '</td><td colspan="5">';
- if ($action == 'nb_gen_max' || $object->frequency > 0)
- {
- print $form->editfieldval($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max?$object->nb_gen_max:'', $object, $user->rights->facture->creer);
- }
- else
- {
- print '';
- }
- print '</td>';
- print '</tr>';
-
- // Status of generated invoices
- print '<tr><td>';
- if ($action == 'auto_validate' || $object->frequency > 0)
- print $form->editfieldkey($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer);
- else
- print $langs->trans("StatusOfGeneratedInvoices");
- print '</td><td colspan="5">';
- $select = 'select;0:'.$langs->trans('BillStatusDraft').',1:'.$langs->trans('BillStatusValidated');
- if ($action == 'auto_validate' || $object->frequency > 0)
- {
- print $form->editfieldval($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer, $select);
- }
- print '</td>';
- print '</tr>';
-
- print '</table>';
-
- print '<br>';
-
- // Frequencry/Recurring section
- if ($object->frequency > 0)
- {
- if (empty($conf->cron->enabled))
- {
- print info_admin($langs->trans("EnableAndSetupModuleCron", $langs->transnoentitiesnoconv("Module2300Name")));
- }
-
- print '<table class="border" width="100%">';
-
- // Nb of generation already done
- print '<tr><td width="20%">'.$langs->trans("NbOfGenerationDone").'</td>';
- print '<td>';
- print $object->nb_gen_done?$object->nb_gen_done:'0';
- print '</td>';
- print '</tr>';
-
- // Date last
- print '<tr><td>';
- print $langs->trans("DateLastGeneration");
- print '</td><td colspan="5">';
- print dol_print_date($object->date_last_gen, 'dayhour');
- print '</td>';
- print '</tr>';
-
- print '</table>';
-
- print '<br>';
- }
-
- // Lines
- print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#add' : '#line_' . GETPOST('lineid')) . '" method="POST">
- <input type="hidden" name="token" value="' . $_SESSION ['newtoken'] . '">
- <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateligne') . '">
- <input type="hidden" name="mode" value="">
- <input type="hidden" name="id" value="' . $object->id . '">
- ';
-
- if (! empty($conf->use_javascript_ajax) && $object->statut == 0) {
- include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
- }
-
- print '<table id="tablelines" class="noborder noshadow" width="100%">';
- // Show object lines
- if (! empty($object->lines))
- {
- //$disableedit=1;
- //$disablemove=1;
- $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 0); // No date selector for template invoice
- }
-
- // Form to add new line
- if ($object->statut == 0 && $user->rights->facture->creer && $action != 'valid' && $action != 'editline')
- {
- if ($action != 'editline')
- {
- $var = true;
-
- // Add free products/services
- $object->formAddObjectLine(0, $mysoc, $soc); // No date selector for template invoice
-
- $parameters = array();
- $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
- }
- }
-
- print "</table>\n";
-
- print "</form>\n";
- dol_fiche_end();
-
- /**
- * Barre d'actions
- */
- print '<div class="tabsAction">';
- //if ($object->statut == Facture::STATUS_DRAFT) // there is no draft status on templates.
- //{
- if ($user->rights->facture->creer)
- {
- if (! empty($object->frequency) && $object->nb_gen_max > 0 && ($object->nb_gen_done >= $object->nb_gen_max))
- {
- print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("MaxGenerationReached")).'">'.$langs->trans("CreateBill").'</a></div>';
- }
- else
- {
- if (empty($object->frequency) || $object->date_when <= $today)
- {
- print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&socid='.$object->thirdparty->id.'&fac_rec='.$object->id.'">'.$langs->trans("CreateBill").'</a></div>';
- }
- else
- {
- print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("DateIsNotEnough")).'">'.$langs->trans("CreateBill").'</a></div>';
- }
- }
- }
- else
- {
- print '<div class="inline-block divButAction"><a class="butActionRefused" href="#">'.$langs->trans("CreateBill").'</a></div>';
- }
- //}
- //if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->supprimer)
- if ($user->rights->facture->supprimer)
- {
- print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&id='.$object->id.'">'.$langs->trans('Delete').'</a></div>';
- }
- print '</div>';
-
-
- print '<div class="fichecenter"><div class="fichehalfleft">';
- print '<a name="builddoc"></a>'; // ancre
-
- // Linked object block
- $somethingshown = $form->showLinkedObjectBlock($object);
-
- print '</div></div>';
- }
- else
- {
- /*
- * List mode
- */
- $sql = "SELECT s.nom as name, s.rowid as socid, f.rowid as facid, f.titre, f.total, f.tva as total_vat, f.total_ttc, f.frequency,";
- $sql.= " f.date_last_gen, f.date_when";
- $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f";
- $sql.= " WHERE f.fk_soc = s.rowid";
- $sql.= " AND f.entity = ".$conf->entity;
- if ($search_ref) $sql .= natural_search('f.titre', $search_ref);
- if ($search_societe) $sql .= natural_search('s.nom', $search_societe);
- if ($search_frequency) $sql .= natural_search('f.frequency', $search_frequency);
- if ($search_montant_ht != '') $sql.= natural_search('f.total', $search_montant_ht, 1);
- if ($search_montant_vat != '') $sql.= natural_search('f.tva', $search_montant_vat, 1);
- if ($search_montant_ttc != '') $sql.= natural_search('f.total_ttc', $search_montant_ttc, 1);
- if ($month > 0)
- {
- if ($year > 0 && empty($day))
- $sql.= " AND f.date_last_gen BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
- else if ($year > 0 && ! empty($day))
- $sql.= " AND f.date_last_gen BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
- else
- $sql.= " AND date_format(f.date_last_gen, '%m') = '".$month."'";
- }
- else if ($year > 0)
- {
- $sql.= " AND f.date_last_gen BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
- }
- if ($month_date_when > 0)
- {
- if ($year_date_when > 0 && empty($day_date_when))
- $sql.= " AND f.date_when BETWEEN '".$db->idate(dol_get_first_day($year_date_when,$month_date_when,false))."' AND '".$db->idate(dol_get_last_day($year_date_when,$month_date_when,false))."'";
- else if ($year_date_when > 0 && ! empty($day_date_when))
- $sql.= " AND f.date_date_when_reglement BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_date_when, $day_date_when, $year_date_when))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_date_when, $day_date_when, $year_date_when))."'";
- else
- $sql.= " AND date_format(f.date_when, '%m') = '".$month_date_when."'";
- }
- else if ($year_date_when > 0)
- {
- $sql.= " AND f.date_when BETWEEN '".$db->idate(dol_get_first_day($year_date_when,1,false))."' AND '".$db->idate(dol_get_last_day($year_date_when,12,false))."'";
- }
- $nbtotalofrecords = 0;
- if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
- {
- $result = $db->query($sql);
- $nbtotalofrecords = $db->num_rows($result);
- }
-
- $sql.= $db->order($sortfield, $sortorder);
- $sql.= $db->plimit($limit+1,$offset);
-
- $resql = $db->query($sql);
- if ($resql)
- {
- $num = $db->num_rows($resql);
-
- $param='&socid='.$socid;
- if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
- if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
- if ($day) $param.='&day='.$day;
- if ($month) $param.='&month='.$month;
- if ($year) $param.='&year=' .$year;
- if ($day_date_when) $param.='&day_date_when='.$day_date_when;
- if ($month_date_when) $param.='&month_date_when='.$month_date_when;
- if ($year_date_when) $param.='&year_date_when=' .$year_date_when;
- if ($search_ref) $param.='&search_ref=' .$search_ref;
- if ($search_societe) $param.='&search_societe=' .$search_societe;
- if ($search_montant_ht != '') $param.='&search_montant_ht='.$search_montant_ht;
- if ($search_montant_vat != '') $param.='&search_montant_vat='.$search_montant_vat;
- if ($search_montant_ttc != '') $param.='&search_montant_ttc='.$search_montant_ttc;
- if ($search_frequency) $param.='&search_frequency=' .$search_frequency;
- if ($option) $param.="&option=".$option;
- if ($optioncss != '') $param.='&optioncss='.$optioncss;
- // Add $param from extra fields
- foreach ($search_array_options as $key => $val)
- {
- $crit=$val;
- $tmpkey=preg_replace('/search_options_/','',$key);
- if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
- }
-
- $massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
-
- print '<form method="POST" name="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
- if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
- print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
- print '<input type="hidden" name="action" value="list">';
- print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
- print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
- print '<input type="hidden" name="viewstatut" value="'.$viewstatut.'">';
- print_barre_liste($langs->trans("RepeatableInvoices"),$page,$_SERVER['PHP_SELF'],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,'title_accountancy.png',0,'','',$limit);
- print $langs->trans("ToCreateAPredefinedInvoice", $langs->transnoentitiesnoconv("ChangeIntoRepeatableInvoice")).'<br><br>';
- $i = 0;
- print '<table class="noborder" width="100%">';
- print '<tr class="liste_titre">';
- print_liste_field_titre($langs->trans("Ref"),$_SERVER['PHP_SELF'],"f.titre","",$param,"",$sortfield,$sortorder);
- print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER['PHP_SELF'],"s.nom","",$param,"",$sortfield,$sortorder);
- print_liste_field_titre($langs->trans("AmountHT"),$_SERVER['PHP_SELF'],"f.total","",$param,'align="right"',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans("AmountVAT"),$_SERVER['PHP_SELF'],"f.tva","",$param,'align="right"',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER['PHP_SELF'],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans("RecurringInvoiceTemplate"),$_SERVER['PHP_SELF'],"f.frequency","",$param,'align="center"',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans("DateLastGeneration"),$_SERVER['PHP_SELF'],"f.date_last_gen","",$param,'align="center"',$sortfield,$sortorder);
- print_liste_field_titre($langs->trans("NextDateToExecution"),$_SERVER['PHP_SELF'],"f.date_when","",$param,'align="center"',$sortfield,$sortorder);
- print_liste_field_titre(''); // Field may contains ling text
- print "</tr>\n";
-
- // Filters lines
- print '<tr class="liste_titre">';
- // Ref
- if (! empty($arrayfields['f.titre']['checked']))
- {
- print '<td class="liste_titre" align="left">';
- print '<input class="flat" size="6" type="text" name="search_ref" value="'.$search_ref.'">';
- print '</td>';
- }
- // Thirpdarty
- if (! empty($arrayfields['s.nom']['checked']))
- {
- print '<td class="liste_titre" align="left"><input class="flat" type="text" size="8" name="search_societe" value="'.$search_societe.'"></td>';
- }
- if (! empty($arrayfields['f.total']['checked']))
- {
- // Amount
- print '<td class="liste_titre" align="right">';
- print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.$search_montant_ht.'">';
- print '</td>';
- }
- if (! empty($arrayfields['f.tva']['checked']))
- {
- // Amount
- print '<td class="liste_titre" align="right">';
- print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.$search_montant_vat.'">';
- print '</td>';
- }
- if (! empty($arrayfields['f.total_ttc']['checked']))
- {
- // Amount
- print '<td class="liste_titre" align="right">';
- print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.$search_montant_ttc.'">';
- print '</td>';
- }
- if (! empty($arrayfields['f.frequency']['checked']))
- {
- // Amount
- print '<td class="liste_titre" align="right">';
- //print '<input class="flat" type="text" size="5" name="search_frequency" value="'.$search_frequency.'">';
- print '</td>';
- }
- // Date invoice
- if (! empty($arrayfields['f.date_last_gen']['checked']))
- {
- print '<td class="liste_titre" align="center">';
- if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
- print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
- $formother->select_year($year?$year:-1,'year',1, 20, 5);
- print '</td>';
- }
- // Date due
- if (! empty($arrayfields['f.date_when']['checked']))
- {
- print '<td class="liste_titre" align="center">';
- if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day_date_when" value="'.$day_date_when.'">';
- print '<input class="flat" type="text" size="1" maxlength="2" name="month_date_when" value="'.$month_date_when.'">';
- $formother->select_year($year_date_when?$year_date_when:-1,'year_date_when',1, 20, 5);
- print '</td>';
- }
- // Extra fields
- if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
- {
- foreach($extrafields->attribute_label as $key => $val)
- {
- if (! empty($arrayfields["ef.".$key]['checked']))
- {
- $align=$extrafields->getAlignFlag($key);
- $typeofextrafield=$extrafields->attribute_type[$key];
- print '<td class="liste_titre'.($align?' '.$align:'').'">';
- if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
- {
- $crit=$val;
- $tmpkey=preg_replace('/search_options_/','',$key);
- $searchclass='';
- if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
- if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
- print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
- }
- print '</td>';
- }
- }
- }
- // Fields from hook
- $parameters=array('arrayfields'=>$arrayfields);
- $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
- print $hookmanager->resPrint;
- // Date creation
- if (! empty($arrayfields['f.datec']['checked']))
- {
- print '<td class="liste_titre">';
- print '</td>';
- }
- // Date modification
- if (! empty($arrayfields['f.tms']['checked']))
- {
- print '<td class="liste_titre">';
- print '</td>';
- }
- // Action column
- print '<td class="liste_titre" align="middle">';
- $searchpitco=$form->showFilterAndCheckAddButtons(0, 'checkforselect', 1);
- print $searchpitco;
- print '</td>';
- print "</tr>\n";
-
-
- if ($num > 0)
- {
- $var=true;
- while ($i < min($num,$limit))
- {
- $objp = $db->fetch_object($resql);
- $var=!$var;
- print "<tr ".$bc[$var].">";
- print '<td><a href="'.$_SERVER['PHP_SELF'].'?id='.$objp->facid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->titre;
- print "</a></td>\n";
- $companystatic->id=$objp->socid;
- $companystatic->name=$objp->name;
- print '<td>'.$companystatic->getNomUrl(1,'customer').'</td>';
- print '<td align="right">'.price($objp->total).'</td>'."\n";
- print '<td align="right">'.price($objp->total_vat).'</td>'."\n";
- print '<td align="right">'.price($objp->total_ttc).'</td>'."\n";
- print '<td align="center">'.yn($objp->frequency?1:0).'</td>';
- print '<td align="center">'.($objp->frequency ? dol_print_date($objp->date_last_gen,'day') : '').'</td>';
- print '<td align="center">'.($objp->frequency ? dol_print_date($objp->date_when,'day') : '').'</td>';
-
- print '<td align="center">';
- if ($user->rights->facture->creer)
- {
- if (empty($objp->frequency) || $db->jdate($objp->date_when) <= $today)
- {
- print '<a href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&socid='.$objp->socid.'&fac_rec='.$objp->facid.'">';
- print $langs->trans("CreateBill").'</a>';
- }
- else
- {
- print $langs->trans("DateIsNotEnough");
- }
- }
- else
- {
- print " ";
- }
- print "</td>";
- print "</tr>\n";
- $i++;
- }
- }
- else print '<tr '.$bc[false].'><td colspan="9">'.$langs->trans("NoneF").'</td></tr>';
- print "</table>";
- $db->free($resql);
- }
- else
- {
- dol_print_error($db);
- }
- }
- }
- llxFooter();
- $db->close();
|