From ea296d8429892dc67a733ba4fa3ede238441d1be Mon Sep 17 00:00:00 2001 From: Grand Philippe Date: Fri, 22 Mar 2013 19:24:26 +0100 Subject: [PATCH 01/10] fix error translation --- htdocs/langs/zh_CN/members.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/zh_CN/members.lang b/htdocs/langs/zh_CN/members.lang index e8ad2efad6f..a664e7290a2 100644 --- a/htdocs/langs/zh_CN/members.lang +++ b/htdocs/langs/zh_CN/members.lang @@ -157,7 +157,7 @@ ShowTypeCard=显示类型'%s' HTPasswordExport=htpassword文件生成 NoThirdPartyAssociatedToMember=无关联的第三方该会员 ThirdPartyDolibarr=Dolibarr第三者 -MembersAndSubscriptions=议员和Suscriptions +MembersAndSubscriptions=议员和Subscriptions // STOP - Lines generated via autotranslator.php tool (2010-06-08 21:22:55). From 3af7ca5ac8722436db37b88e75b689aa617465c9 Mon Sep 17 00:00:00 2001 From: eldy Date: Sat, 23 Mar 2013 12:23:09 +0100 Subject: [PATCH 02/10] Work on revenue stamp feature. --- htdocs/core/class/commonobject.class.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 975765d12b4..dcd96ed6734 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1509,6 +1509,9 @@ abstract class CommonObject $this->total_localtax2 += $obj->total_localtax2; $this->total_ttc += $obj->total_ttc; + // Add revenue stamp to total + $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; + // Check if there is a global invoice tax for this vat rate // FIXME: We should have no database access into this function. Also localtax 7 seems to have problem so i add condition to avoid it into standard usage without loosing it. if (! empty($conf->global->MAIN_USE_LOCALTAX_TYPE_7)) From c8d6e9e44a37cc14143b40f661feff3306b3138e Mon Sep 17 00:00:00 2001 From: eldy Date: Sat, 23 Mar 2013 12:33:25 +0100 Subject: [PATCH 03/10] Fix: List of customers to build invoice or order --- htdocs/commande/fiche.php | 2 +- htdocs/compta/facture.php | 2 +- htdocs/contrat/fiche.php | 2 +- htdocs/core/class/html.form.class.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 52b7761adbe..bb9c9117f24 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -1487,7 +1487,7 @@ if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! G else { print ''; - print $form->select_company('','socid','s.client = 1',1); + print $form->select_company('','socid','s.client = 1 OR s.client = 3',1); print ''; } print ''."\n"; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 96fca70af4c..77294a3c459 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1916,7 +1916,7 @@ if ($action == 'create') else { print ''; - print $form->select_company('','socid','s.client = 1',1); + print $form->select_company('','socid','s.client = 1 OR s.client = 3',1); print ''; } print ''."\n"; diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php index 902dde79f17..de9ce68e6b3 100644 --- a/htdocs/contrat/fiche.php +++ b/htdocs/contrat/fiche.php @@ -827,7 +827,7 @@ if ($action == 'create') else { print ''; - print $form->select_company('','socid','s.client = 1',1); + print $form->select_company('','socid','s.client = 1 OR s.client = 3',1); print ''; } print ''."\n"; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 941865da45a..4807ec768fa 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -678,7 +678,7 @@ class Form if (!$user->rights->societe->client->voir && !$user->societe_id) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.entity IN (".getEntity('societe', 1).")"; if (! empty($user->societe_id)) $sql.= " AND s.rowid = ".$user->societe_id; - if ($filter) $sql.= " AND ".$filter; + 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; $sql.= " ORDER BY nom ASC"; From 90025f9c13cf0a4270fd76ecfc9be9a6e7f52044 Mon Sep 17 00:00:00 2001 From: eldy Date: Sat, 23 Mar 2013 13:07:25 +0100 Subject: [PATCH 04/10] Work on revenue stamp --- htdocs/compta/facture.php | 41 +++++++++++++++++-- htdocs/compta/facture/class/facture.class.php | 6 ++- htdocs/core/class/commonobject.class.php | 6 +-- htdocs/langs/en_US/bills.lang | 1 + htdocs/langs/fr_FR/bills.lang | 1 + 5 files changed, 48 insertions(+), 7 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 77294a3c459..aa6f3cfec07 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -302,6 +302,14 @@ else if ($action == 'setpaymentterm' && $user->rights->facture->creer) $result=$object->update($user); if ($result < 0) dol_print_error($db,$object->error); } +else if ($action == 'setrevenuestamp' && $user->rights->facture->creer) +{ + $object->fetch($id); + $object->revenuestamp=GETPOST('revenuestamp'); + $result=$object->update($user); + $object->update_price(1); + if ($result < 0) dol_print_error($db,$object->error); +} else if ($action == 'setremisepercent' && $user->rights->facture->creer) { $object->fetch($id); @@ -2745,6 +2753,7 @@ else if ($id > 0 || ! empty($ref)) /* * List of payments */ + $selleruserevenustamp=empty($conf->global->MAIN_USE_REVENUE_STAMP)?0:1; // TODO Add method societe->useRevenueStamp() to look into table llx_c_revenue_stamp if there is one line for country $sign=1; if ($object->type == 2) $sign=-1; @@ -2752,11 +2761,10 @@ else if ($id > 0 || ! empty($ref)) $nbrows=8; $nbcols=2; if (! empty($conf->projet->enabled)) $nbrows++; if (! empty($conf->banque->enabled)) $nbcols++; - - //Local taxes if($mysoc->localtax1_assuj=="1") $nbrows++; if($mysoc->localtax2_assuj=="1") $nbrows++; - + if ($selleruserevenustamp) $nbrows++; + print ''; print ''; @@ -3042,6 +3050,33 @@ else if ($id > 0 || ! empty($ref)) print ''; } + // Revenue stamp + if ($selleruserevenustamp) // Test company use revenue stamp + { + print ''; + } + + // Total with tax print ''; // Statut diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index f3427ee5d4b..38995fdebb9 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -75,6 +75,7 @@ class Facture extends CommonInvoice var $total_ht=0; var $total_tva=0; var $total_ttc=0; + var $revenuestamp; var $note; // deprecated var $note_private; var $note_public; @@ -795,7 +796,8 @@ class Facture extends CommonInvoice if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1; - $sql = 'SELECT f.rowid,f.facnumber,f.ref_client,f.ref_ext,f.ref_int,f.type,f.fk_soc,f.amount,f.tva, f.localtax1, f.localtax2, f.total,f.total_ttc,f.remise_percent,f.remise_absolue,f.remise'; + $sql = 'SELECT f.rowid,f.facnumber,f.ref_client,f.ref_ext,f.ref_int,f.type,f.fk_soc,f.amount,f.tva, f.localtax1, f.localtax2, f.total, f.total_ttc, f.revenuestamp'; + $sql.= ', f.remise_percent, f.remise_absolue, f.remise'; $sql.= ', f.datef as df'; $sql.= ', f.date_lim_reglement as dlr'; $sql.= ', f.datec as datec'; @@ -841,6 +843,7 @@ class Facture extends CommonInvoice $this->total_localtax1 = $obj->localtax1; $this->total_localtax2 = $obj->localtax2; $this->total_ttc = $obj->total_ttc; + $this->revenuestamp = $obj->revenuestamp; $this->paye = $obj->paye; $this->close_code = $obj->close_code; $this->close_note = $obj->close_note; @@ -1050,6 +1053,7 @@ class Facture extends CommonInvoice $sql.= " localtax2=".(isset($this->total_localtax2)?$this->total_localtax2:"null").","; $sql.= " total=".(isset($this->total_ht)?$this->total_ht:"null").","; $sql.= " total_ttc=".(isset($this->total_ttc)?$this->total_ttc:"null").","; + $sql.= " revenuestamp=".((isset($this->revenuestamp) && $this->revenuestamp != '')?$this->revenuestamp:"null").","; $sql.= " fk_statut=".(isset($this->statut)?$this->statut:"null").","; $sql.= " fk_user_author=".(isset($this->user_author)?$this->user_author:"null").","; $sql.= " fk_user_valid=".(isset($this->fk_user_valid)?$this->fk_user_valid:"null").","; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index dcd96ed6734..79a471a0251 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1509,9 +1509,6 @@ abstract class CommonObject $this->total_localtax2 += $obj->total_localtax2; $this->total_ttc += $obj->total_ttc; - // Add revenue stamp to total - $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; - // Check if there is a global invoice tax for this vat rate // FIXME: We should have no database access into this function. Also localtax 7 seems to have problem so i add condition to avoid it into standard usage without loosing it. if (! empty($conf->global->MAIN_USE_LOCALTAX_TYPE_7)) @@ -1559,6 +1556,9 @@ abstract class CommonObject $i++; } + // Add revenue stamp to total + $this->total_ttc += isset($this->revenuestamp)?$this->revenuestamp:0; + $this->db->free($resql); // Now update global field total_ht, total_ttc and tva diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 785f131b61b..1ce21c7a8f6 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -390,6 +390,7 @@ AllCompletelyPayedInvoiceWillBeClosed=All invoice with no remain to pay will be ToMakePayment=Pay ToMakePaymentBack=Pay back ListOfYourUnpaidInvoices=List of unpaid invoices +RevenueStamp=Revenue stamp ##### Types de contacts ##### TypeContact_facture_internal_SALESREPFOLL=Representative following-up customer invoice TypeContact_facture_external_BILLING=Customer invoice contact diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index 51424be1cbf..e5955167dd8 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -387,6 +387,7 @@ AllCompletelyPayedInvoiceWillBeClosed=Toutes les factures avec un reste à payer ToMakePayment=Payer ToMakePaymentBack=Rembourser ListOfYourUnpaidInvoices=Liste des factures impayées +RevenueStamp=Timbre fiscal ##### Types de contacts ##### TypeContact_facture_internal_SALESREPFOLL=Responsable suivi facture client TypeContact_facture_external_BILLING=Contact client facturation From fbf8d410d21987c3fd0dd27060e21f1887e90229 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 23 Mar 2013 17:34:23 +0100 Subject: [PATCH 05/10] New: Support revenue stamp onto invoices --- ChangeLog | 1 + htdocs/admin/company.php | 8 +-- htdocs/compta/facture.php | 46 ++++++------- .../modules/facture/doc/pdf_crabe.modules.php | 11 +++ .../install/mysql/data/llx_c_revenuestamp.sql | 13 +--- htdocs/install/mysql/data/llx_c_tva.sql | 14 ++-- .../install/mysql/migration/3.3.0-3.4.0.sql | 15 ++++- htdocs/install/mysql/tables/llx_c_tva.sql | 4 +- htdocs/societe/class/societe.class.php | 67 ++++++++++++------- 9 files changed, 103 insertions(+), 76 deletions(-) diff --git a/ChangeLog b/ChangeLog index 66e4a8cfd89..db9fc3b9f8e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ English Dolibarr ChangeLog ***** ChangeLog for 3.4 compared to 3.3 ***** For users: +- New: Support revenue stamp onto invoices. - New: Add a tab "consumption" on thirdparties to list products bought/sells. - New: Some performance enhancements. - New: Can attach files onto trip and expenses modules. diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 55ad5902e13..55a8a8b8b60 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -547,7 +547,7 @@ if ($action == 'edit' || $action == 'updateedit') /* * Local Taxes */ - if ($mysoc->hasLocalTax(1)) + if ($mysoc->useLocalTax(1)) { // Local Tax 1 print '
'; @@ -579,7 +579,7 @@ if ($action == 'edit' || $action == 'updateedit') print "\n"; print "
'.price($object->total_localtax2,1,'',1,-1,-1,$conf->currency).'
'; + print ''; + if ($action != 'editrevenuestamp' && ! empty($object->brouillon) && $user->rights->facture->creer) print ''; + print '
'; + print $langs->trans('RevenueStamp'); + print 'id.'">'.img_edit($langs->trans('SetRevenuStamp'),1).'
'; + print '
'; + if ($action == 'editrevenuestamp') + { + print '
'; + print ''; + print ''; + print ''; + print ' '; + print '
'; + } + else + { + print price($object->revenuestamp,1,'',1,-1,-1,$conf->currency); + } + print '
'.$langs->trans('AmountTTC').''.price($object->total_ttc,1,'',1,-1,-1,$conf->currency).'
"; } - if ($mysoc->hasLocalTax(2)) + if ($mysoc->useLocalTax(2)) { // Local Tax 2 print '
'; @@ -927,7 +927,7 @@ else /* * Local Taxes */ - if ($mysoc->hasLocalTax(1)) + if ($mysoc->useLocalTax(1)) { // Local Tax 1 print '
'; @@ -960,7 +960,7 @@ else print ""; } - if ($mysoc->hasLocalTax(2)) + if ($mysoc->useLocalTax(2)) { // Local Tax 2 print '
'; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index aa6f3cfec07..f792d7c6e20 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -377,22 +377,22 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->factu $object->fetch_thirdparty(); // Check parameters - + // Check for mandatory prof id for ($i = 1; $i < 5; $i++) { - + $idprof_mandatory ='SOCIETE_IDPROF'.($i).'_INVOICE_MANDATORY'; $idprof='idprof'.$i; if (! $object->thirdparty->$idprof && ! empty($conf->global->$idprof_mandatory)) { if (! $error) $langs->load("errors"); $error++; - + setEventMessage($langs->trans('ErrorProdIdIsMandatory',$langs->transcountry('ProfId'.$i, $object->thirdparty->country_code)),'errors'); } - } - + } + //Check for warehouse if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->hasProductsOrServices(1)) { @@ -403,7 +403,7 @@ else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->factu $action=''; } } - + if (! $error) { $result = $object->validate($user,'',$idwarehouse); @@ -625,7 +625,7 @@ else if ($action == 'add' && $user->rights->facture->creer) $db->begin(); $error=0; - + // Get extra fields foreach($_POST as $key => $value) { @@ -1638,7 +1638,7 @@ else if ($action == 'builddoc') // En get ou en post if (GETPOST('model')) $object->setDocModel($user, GETPOST('model')); if (GETPOST('fk_bank')) $object->fk_bank=GETPOST('fk_bank'); - + // Define output language $outputlangs = $langs; $newlang=''; @@ -2280,10 +2280,10 @@ else if ($id > 0 || ! empty($ref)) */ $result=$object->fetch($id,$ref); - + // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label('facture'); - + if ($result > 0) { if ($user->societe_id>0 && $user->societe_id!=$object->socid) accessforbidden('',0); @@ -2292,11 +2292,12 @@ else if ($id > 0 || ! empty($ref)) $soc = new Societe($db); $soc->fetch($object->socid); + $selleruserevenustamp=$mysoc->useRevenueStamp(); $totalpaye = $object->getSommePaiement(); $totalcreditnotes = $object->getSumCreditNotesUsed(); $totaldeposits = $object->getSumDepositsUsed(); - //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits; + //print "totalpaye=".$totalpaye." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits." selleruserrevenuestamp=".$selleruserevenustamp; // We can also use bcadd to avoid pb with floating points // For example print 239.2 - 229.3 - 9.9; does not return 0. @@ -2753,7 +2754,6 @@ else if ($id > 0 || ! empty($ref)) /* * List of payments */ - $selleruserevenustamp=empty($conf->global->MAIN_USE_REVENUE_STAMP)?0:1; // TODO Add method societe->useRevenueStamp() to look into table llx_c_revenue_stamp if there is one line for country $sign=1; if ($object->type == 2) $sign=-1; @@ -2764,7 +2764,7 @@ else if ($id > 0 || ! empty($ref)) if($mysoc->localtax1_assuj=="1") $nbrows++; if($mysoc->localtax2_assuj=="1") $nbrows++; if ($selleruserevenustamp) $nbrows++; - + print ''; print ''; @@ -3039,12 +3039,12 @@ else if ($id > 0 || ! empty($ref)) print ''; // Amount Local Taxes - if ($mysoc->localtax1_assuj=="1") //Localtax1 RE + if ($mysoc->localtax1_assuj=="1" && $mysoc->useLocalTax(1)) //Localtax1 (example RE) { print ''; print ''; } - if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF + if ($mysoc->localtax2_assuj=="1" && $mysoc->useLocalTax(2)) //Localtax2 (example IRPF) { print ''; print ''; @@ -3075,7 +3075,7 @@ else if ($id > 0 || ! empty($ref)) } print ''; } - + // Total with tax print ''; @@ -3113,14 +3113,14 @@ else if ($id > 0 || ! empty($ref)) print ''; print ''; } - + // Other attributes $res=$object->fetch_optionals($object->id,$extralabels); $parameters=array('colspan' => ' colspan="2"'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook) && ! empty($extrafields->attribute_label)) { - + if ($action == 'edit_extras') { print ''; @@ -3128,8 +3128,8 @@ else if ($id > 0 || ! empty($ref)) print ''; print ''; } - - + + foreach($extrafields->attribute_label as $key=>$label) { $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]); @@ -3153,16 +3153,16 @@ else if ($id > 0 || ! empty($ref)) print ''."\n"; } } - + if(count($extrafields->attribute_label) > 0) { - + if ($action == 'edit_extras' && $user->rights->facture->creer) { print ''; - + } else { if ($object->statut == 0 && $user->rights->facture->creer) diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index ef7698d0564..15ee4e29aba 100755 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -1020,6 +1020,17 @@ class pdf_crabe extends ModelePDFFactures //} } + // Revenue stamp + if (price2num($object->revenuestamp) != 0) + { + $index++; + $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("RevenueStamp"), $useborder, 'L', 1); + + $pdf->SetXY($col2x, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($largcol2, $tab2_hl, price($sign * $object->revenuestamp), $useborder, 'R', 1); + } + // Total TTC $index++; $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); diff --git a/htdocs/install/mysql/data/llx_c_revenuestamp.sql b/htdocs/install/mysql/data/llx_c_revenuestamp.sql index 8d998111218..040a8370485 100644 --- a/htdocs/install/mysql/data/llx_c_revenuestamp.sql +++ b/htdocs/install/mysql/data/llx_c_revenuestamp.sql @@ -1,13 +1,4 @@ --- Copyright (C) 2001-2004 Rodolphe Quiedeville --- Copyright (C) 2003 Jean-Louis Bergamo -- Copyright (C) 2004-2011 Laurent Destailleur --- Copyright (C) 2004 Benoit Mortier --- Copyright (C) 2004 Guillaume Delecourt --- Copyright (C) 2005-2009 Regis Houssin --- Copyright (C) 2007 Patrick Raguin --- Copyright (C) 2010-2011 Juanjo Menent --- Copyright (C) 2012 Sebastian Neuwert --- Copyright (C) 2012 Ricardo Schluter -- -- 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 @@ -35,5 +26,5 @@ delete from llx_c_revenuestamp; --- TUNISIA -- -insert into llx_c_revenuestamp(rowid,fk_pays,taux,note,active) values (101, 10, '0.4', 'Timbre fiscal', 1); +-- TUNISIA (id country=10) -- +insert into llx_c_revenuestamp(rowid,fk_pays,taux,note,active) values (101, 10, 0.4, 'Revenue stamp tunisia', 1); diff --git a/htdocs/install/mysql/data/llx_c_tva.sql b/htdocs/install/mysql/data/llx_c_tva.sql index b5f578f579b..b6d38949451 100644 --- a/htdocs/install/mysql/data/llx_c_tva.sql +++ b/htdocs/install/mysql/data/llx_c_tva.sql @@ -219,13 +219,13 @@ insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 6 insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 64, 6, '0','0','VAT Rate 0', 1); -- TUNISIA (id country=10) -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (101,10, '6','0','VAT 6%', 1, 1, '4', 0.4, '7'); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (102,10, '12','0','VAT 12%',1, 1, '4', 0.4, '7'); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (103,10, '18','0','VAT 18%',1, 1, '4', 0.4, '7'); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (104,10, '7.5','0','VAT 6% Majoré à 25% (7.5%)',1, 1, '4', 0.4, '7'); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (105,10, '15','0','VAT 12% Majoré à 25% (15%)',1, 1, '4', 0.4, '7'); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (106,10, '22.5','0','VAT 18% Majoré à 25% (22.5%)',1, 1, '4', 0.4, '7'); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (107,10, '0','0','VAT Rate 0', 1, 1, '4', 0.4, '7'); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (101,10, '6','0','VAT 6%', 1, 1, '4', 0, null); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (102,10, '12','0','VAT 12%',1, 1, '4', 0, null); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (103,10, '18','0','VAT 18%',1, 1, '4', 0, null); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (104,10, '7.5','0','VAT 6% Majoré à 25% (7.5%)',1, 1, '4', 0, null); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (105,10, '15','0','VAT 12% Majoré à 25% (15%)',1, 1, '4', 0, null); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (106,10, '22.5','0','VAT 18% Majoré à 25% (22.5%)',1, 1, '4', 0, null); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active,localtax1,localtax1_type,localtax2,localtax2_type) values (107,10, '0','0','VAT Rate 0', 1, 1, '4', 0, null); -- UKRAINE (id country=226) INSERT INTO llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (2261,226, '20','0','VAT standart rate',1); diff --git a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql index e6b82dc565e..571ba7373a2 100755 --- a/htdocs/install/mysql/migration/3.3.0-3.4.0.sql +++ b/htdocs/install/mysql/migration/3.3.0-3.4.0.sql @@ -130,8 +130,6 @@ CREATE TABLE llx_c_revenuestamp insert into llx_c_revenuestamp(rowid,fk_pays,taux,note,active) values (101, 10, '0.4', 'Timbre fiscal', 1); -ALTER TABLE llx_actioncomm ADD COLUMN code varchar(32) NULL after fk_action; - ALTER TABLE llx_c_tva MODIFY COLUMN localtax1_type varchar(10) NOT NULL DEFAULT '0'; ALTER TABLE llx_c_tva MODIFY COLUMN localtax2_type varchar(10) NOT NULL DEFAULT '0'; ALTER TABLE llx_commande_fournisseurdet MODIFY COLUMN localtax1_type varchar(10) NOT NULL DEFAULT '0'; @@ -148,6 +146,13 @@ ALTER TABLE llx_facturedet MODIFY COLUMN localtax1_type varchar(10) NOT NULL DEF ALTER TABLE llx_facturedet MODIFY COLUMN localtax2_type varchar(10) NOT NULL DEFAULT '0'; ALTER TABLE llx_propaldet MODIFY COLUMN localtax1_type varchar(10) NOT NULL DEFAULT '0'; ALTER TABLE llx_propaldet MODIFY COLUMN localtax2_type varchar(10) NOT NULL DEFAULT '0'; +-- No more use type 7, use revenuse stamp instead +UPDATE llx_c_tva set localtax1=0, localtax1_type='0' where localtax1_type = '7'; +UPDATE llx_c_tva set localtax2=0, localtax2_type='0' where localtax2_type = '7'; + + +ALTER TABLE llx_actioncomm ADD COLUMN code varchar(32) NULL after fk_action; + ALTER TABLE llx_holiday ADD COLUMN note text; ALTER TABLE llx_holiday ADD COLUMN note_public text; @@ -197,5 +202,9 @@ ALTER TABLE llx_societe MODIFY COLUMN zip varchar(25); ALTER TABLE llx_user ADD COLUMN address varchar(255); ALTER TABLE llx_user ADD COLUMN zip varchar(25); ALTER TABLE llx_user ADD COLUMN town varchar(50); -ALTER TABLE llx_user ADD COLUMN fk_state integer DEFAULT 0; -- +ALTER TABLE llx_user ADD COLUMN fk_state integer DEFAULT 0; ALTER TABLE llx_user ADD COLUMN fk_country integer DEFAULT 0; + + + + diff --git a/htdocs/install/mysql/tables/llx_c_tva.sql b/htdocs/install/mysql/tables/llx_c_tva.sql index 219b1fb9744..46aa3632faa 100644 --- a/htdocs/install/mysql/tables/llx_c_tva.sql +++ b/htdocs/install/mysql/tables/llx_c_tva.sql @@ -24,9 +24,9 @@ create table llx_c_tva fk_pays integer NOT NULL, taux double NOT NULL, localtax1 double NOT NULL DEFAULT 0, - localtax1_type varchar(10) NOT NULL DEFAULT '0', + localtax1_type varchar(10) NOT NULL DEFAULT '0', localtax2 double NOT NULL DEFAULT 0, - localtax2_type varchar(10) NOT NULL DEFAULT '0', + localtax2_type varchar(10) NOT NULL DEFAULT '0', recuperableonly integer NOT NULL DEFAULT 0, note varchar(128), active tinyint DEFAULT 1 NOT NULL, diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index c87a6ef11f4..ecf387e13c2 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -82,7 +82,9 @@ class Societe extends CommonObject var $idprof1; // IdProf1 (Ex: Siren in France) var $idprof2; // IdProf2 (Ex: Siret in France) var $idprof3; // IdProf3 (Ex: Ape in France) - var $idprof4; // IdProf4 (Ex: RCS in France) + var $idprof4; // IdProf4 (Ex: RCS in France) + var $idprof5; // IdProf5 + var $idprof6; // IdProf6 var $prefix_comm; @@ -2599,40 +2601,53 @@ class Societe extends CommonObject } /** - * Check if localtax define for company - * Used to build previews or test instances. - * id must be 0 if object instance is a specimen. + * Check if thirdparty may using localtax or not * - * @param localTaxNum $localTaxNum 1 or 2 - * @return boolean true / false + * @param int $localTaxNum To get info for only localtax1 or localtax2 + * @return array array(0=>boolean, 1=>boolean) */ - function hasLocalTax($localTaxNum) { - global $user,$langs,$conf; + function useLocalTax($localTaxNum=0) + { + $sql = "SELECT t.localtax1, t.localtax2"; + $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p"; + $sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$this->country_code."'"; + $sql .= " AND t.active = 1"; + if (empty($localTaxNum)) $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')"; + elseif ($localTaxNum == 1) $sql .= " AND t.localtax1_type <> '0'"; + elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'"; - // check parameter - if ($localTaxNum != 1 && $localTaxNum != 2) - return false; + dol_syslog("useLocalTax sql=".$sql); + $resql=$this->db->query($sql); + if ($resql) + { + return ($this->db->num_rows($resql) > 0); + } + else return false; + } - // Search local taxes - $sql = "SELECT t.localtax1, t.localtax2"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_pays as p"; - $sql .= " WHERE t.fk_pays = p.rowid AND p.code = '".$this->country_code."'"; - $sql .= " AND t.active = 1"; - if ($localTaxNum == 1) - $sql .= " AND t.localtax1 <> 0"; - elseif ($localTaxNum == 2) - $sql .= " AND t.localtax2 <> 0"; + /** + * Check if thirdparty is from a country using revenue stamps + * + * @return boolean Yes or no + */ + function useRevenueStamp() + { + $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."c_revenuestamp as r, ".MAIN_DB_PREFIX."c_pays as p"; + $sql .= " WHERE r.fk_pays = p.rowid AND p.code = '".$this->country_code."'"; + $sql .= " AND r.active = 1"; - dol_syslog("get_localtax sql=".$sql); + dol_syslog("useRevenueStamp sql=".$sql); $resql=$this->db->query($sql); if ($resql) { - return ($this->db->num_rows($resql) > 0); - + $obj=$this->db->fetch_object($resql); + return (($obj->nb > 0)?true:false); } else - return false; - + { + $this->error=$this->db->lasterror(); + return false; + } } /** @@ -2752,7 +2767,7 @@ class Societe extends CommonObject /** * Set commnunication level * - * @param User $user Utilisateur qui definie la remise + * @param User $user User making change * @return int <0 if KO, >0 if OK */ function set_commnucation_level($user) From 4d527d26af5609f343783d563685050de9ea08c3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 23 Mar 2013 17:40:18 +0100 Subject: [PATCH 06/10] New: support full address into user cards. --- htdocs/user/class/user.class.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index feb1b6164e0..37ff6735df5 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -912,6 +912,11 @@ class User extends CommonObject $this->office_phone = $contact->phone_pro; $this->office_fax = $contact->fax; $this->user_mobile = $contact->phone_mobile; + $this->address = $contact->address; + $this->zip = $contact->zip; + $this->town = $contact->town; + $this->state_id = $contact->state_id; + $this->country_id = $contact->country_id; if (empty($login)) $login=strtolower(substr($contact->firstname, 0, 4)) . strtolower(substr($contact->lastname, 0, 4)); $this->login = $login; @@ -974,11 +979,16 @@ class User extends CommonObject // Positionne parametres $this->admin = 0; - $this->lastname = $member->lastname; - $this->firstname = $member->firstname; - $this->email = $member->email; - $this->fk_member = $member->id; - $this->pass = $member->pass; + $this->lastname = $member->lastname; + $this->firstname = $member->firstname; + $this->email = $member->email; + $this->fk_member = $member->id; + $this->pass = $member->pass; + $this->address = $member->address; + $this->zip = $member->zip; + $this->town = $member->town; + $this->state_id = $member->state_id; + $this->country_id = $member->country_id; if (empty($login)) $login=strtolower(substr($member->firstname, 0, 4)) . strtolower(substr($member->lastname, 0, 4)); $this->login = $login; @@ -1120,6 +1130,11 @@ class User extends CommonObject $sql.= ", firstname = '".$this->db->escape($this->firstname)."'"; $sql.= ", login = '".$this->db->escape($this->login)."'"; $sql.= ", admin = ".$this->admin; + $sql.= ", address = '".$this->db->escape($this->address)."'"; + $sql.= ", zip = '".$this->db->escape($this->zip)."'"; + $sql.= ", town = '".$this->db->escape($this->town)."'"; + $sql.= ", fk_state = '".$this->db->escape($this->state_id)."'"; + $sql.= ", fk_country = '".$this->db->escape($this->country_id)."'"; $sql.= ", office_phone = '".$this->db->escape($this->office_phone)."'"; $sql.= ", office_fax = '".$this->db->escape($this->office_fax)."'"; $sql.= ", user_mobile = '".$this->db->escape($this->user_mobile)."'"; From 73de8d169f5fbb333df96058121be69f4b924360 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 23 Mar 2013 18:04:46 +0100 Subject: [PATCH 07/10] Fix: Avoid call method on non object error --- .../core/class/commondocgenerator.class.php | 28 +++++++++---------- .../doc/doc_generic_invoice_odt.modules.php | 10 +++---- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index faccaa31545..9561aa288fb 100755 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -185,11 +185,11 @@ abstract class CommonDocGenerator } $array_thirdparty=array_merge($array_thirdparty,array('company_options_'.$key => $object->array_options['options_'.$key])); } - } + } return $array_thirdparty; } - + /** * Define array with couple substitution key => substitution value * @@ -201,7 +201,7 @@ abstract class CommonDocGenerator function get_substitutionarray_propal($object,$outputlangs,$array_key='object') { global $conf; - + $array_propal=array( $array_key.'_id'=>$object->id, $array_key.'_ref'=>$object->ref, @@ -224,14 +224,14 @@ abstract class CommonDocGenerator $array_key.'_note_private'=>$object->note, $array_key.'_note'=>$object->note_public, ); - + // Add vat by rates foreach ($object->lines as $line) { if (empty($array_propal[$array_key.'_total_vat_'.$line->tva_tx])) $array_propal[$array_key.'_total_vat_'.$line->tva_tx]=0; $array_propal[$array_key.'_total_vat_'.$line->tva_tx]+=$line->total_tva; } - + // Retrieve extrafields if(is_array($object->array_options) && count($object->array_options)) { @@ -240,12 +240,12 @@ abstract class CommonDocGenerator $extrafields = new ExtraFields($this->db); $extralabels = $extrafields->fetch_name_optionals_label('propal',true); $object->fetch_optionals($object->id,$extralabels); - + $array_propal = $this->fill_substitutionarray_with_extrafields($object,$array_propal,$extrafields,$array_key,$outputlangs); } return $array_propal; } - + /** * Define array with couple substitution key => substitution value @@ -257,7 +257,7 @@ abstract class CommonDocGenerator function get_substitutionarray_propal_lines($line,$outputlangs) { global $conf; - + return array( 'line_fulldesc'=>doc_getlinedesc($line,$outputlangs), 'line_product_ref'=>$line->product_ref, @@ -274,7 +274,7 @@ abstract class CommonDocGenerator 'line_date_end'=>$line->date_end ); } - + /** * Fill array with couple extrafield key => extrafield value * @@ -309,14 +309,14 @@ abstract class CommonDocGenerator { $object->array_options['options_'.$key] = ($object->array_options['options_'.$key]!="0000-00-00 00:00:00"?dol_print_date($object->array_options['options_'.$key],'dayhour'):''); } - $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key => $object->array_options['options_'.$key])); + $array_to_fill=array_merge($array_to_fill,array($array_key.'_options_'.$key => $object->array_options['options_'.$key])); } - + return $array_to_fill; - + } - - + + /** * Rect pdf * diff --git a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php index 957b5d85428..977de72d164 100644 --- a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php +++ b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php @@ -139,7 +139,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures if (empty($resarray['object_total_vat_'.$line->tva_tx])) $resarray['object_total_vat_'.$line->tva_tx]=0; $resarray['object_total_vat_'.$line->tva_tx]+=$line->total_tva; } - + // Retrieve extrafields if(is_array($object->array_options) && count($object->array_options)) { @@ -148,7 +148,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures $extrafields = new ExtraFields($this->db); $extralabels = $extrafields->fetch_name_optionals_label('facture',true); $object->fetch_optionals($object->id,$extralabels); - + $resarray = $this->fill_substitutionarray_with_extrafields($object,$resarray,$extrafields,$array_key='object',$outputlangs); } return $resarray; @@ -358,14 +358,14 @@ class doc_generic_invoice_odt extends ModelePDFFactures { $socobject=$object->client; } - + // Fetch info for linked propal $linked_propal = $object->fetchObjectLinked('','','',''); print '
';
                 //print_r($object->linkedObjects['propal']); exit;
 
                 $propal_object = $object->linkedObjects['propal'][0];
-                
+
                 // Make substitution
                 $substitutionarray=array(
                     '__FROM_NAME__' => $this->emetteur->nom,
@@ -415,7 +415,7 @@ class doc_generic_invoice_odt extends ModelePDFFactures
 				$array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs);
 				$array_thirdparty=$this->get_substitutionarray_thirdparty($socobject,$outputlangs);
 				$array_objet=$this->get_substitutionarray_object($object,$outputlangs);
-				$array_propal=$this->get_substitutionarray_propal($propal_object,$outputlangs,'propal');
+				$array_propal=is_object($propal_object)?$this->get_substitutionarray_propal($propal_object,$outputlangs,'propal'):array();
 
 				$tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_objet,$array_propal);
 				complete_substitutions_array($tmparray, $outputlangs, $object);

From 9fe0d2cdd25927b2909c34ed4aea94d1b4998a7a Mon Sep 17 00:00:00 2001
From: Laurent Destailleur 
Date: Sat, 23 Mar 2013 18:22:25 +0100
Subject: [PATCH 08/10] Fix: Removed a lors 'pre'. Also accurency of data must
 not be overwrite by odt template engine (to be compatible with all countries
 precision).

---
 .../doc/doc_generic_invoice_odt.modules.php       | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php
index 977de72d164..ee80dbbb141 100644
--- a/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php
+++ b/htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php
@@ -121,16 +121,16 @@ class doc_generic_invoice_odt extends ModelePDFFactures
         	'object_payment_mode'=>($outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code)!='PaymentType'.$object->mode_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentType'.$object->mode_reglement_code):$object->mode_reglement),
         	'object_payment_term_code'=>$object->cond_reglement_code,
         	'object_payment_term'=>($outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code)!='PaymentCondition'.$object->cond_reglement_code?$outputlangs->transnoentitiesnoconv('PaymentCondition'.$object->cond_reglement_code):$object->cond_reglement),
-        	'object_total_ht'=>price2num($object->total_ht,2),
-            'object_total_vat'=>price2num($object->total_tva,2),
-            'object_total_ttc'=>price2num($object->total_ttc,2),
+        	'object_total_ht'=>price2num($object->total_ht),
+            'object_total_vat'=>price2num($object->total_tva),
+            'object_total_ttc'=>price2num($object->total_ttc),
             'object_total_discount_ht' => price2num($object->getTotalDiscount(), 0, $outputlangs),
             'object_vatrate'=>(isset($object->tva)?vatrate($object->tva):''),
             'object_note_private'=>$object->note,
             'object_note'=>$object->note_public,
         	// Payments
             'object_already_payed'=>$alreadypayed,
-            'object_remain_to_pay'=>price2num($object->total_ttc - $sumpayed,2)
+            'object_remain_to_pay'=>price2num($object->total_ttc - $sumpayed)
         );
 
         // Add vat by rates
@@ -174,9 +174,9 @@ class doc_generic_invoice_odt extends ModelePDFFactures
             'line_up'=>price($line->subprice, 0, $outputlangs),
             'line_qty'=>$line->qty,
             'line_discount_percent'=>($line->remise_percent?$line->remise_percent.'%':''),
-            'line_price_ht'=>price2num($line->total_ht, 2),
-            'line_price_ttc'=>price2num($line->total_ttc, 2),
-            'line_price_vat'=>price2num($line->total_tva, 2),
+            'line_price_ht'=>price2num($line->total_ht),
+            'line_price_ttc'=>price2num($line->total_ttc),
+            'line_price_vat'=>price2num($line->total_tva),
             'line_date_start'=>dol_print_date($line->date_start, 'day', false, $outputlangs),
             'line_date_end'=>dol_print_date($line->date_end, 'day', false, $outputlangs),
         );
@@ -361,7 +361,6 @@ class doc_generic_invoice_odt extends ModelePDFFactures
 
                 // Fetch info for linked propal
                 $linked_propal = $object->fetchObjectLinked('','','','');
-                print '
';
                 //print_r($object->linkedObjects['propal']); exit;
 
                 $propal_object = $object->linkedObjects['propal'][0];

From 7f61061805e963ef30f072cb6ecc7ee59e785c2f Mon Sep 17 00:00:00 2001
From: Grand Philippe 
Date: Sat, 23 Mar 2013 19:08:02 +0100
Subject: [PATCH 09/10] fix : wrong URL

---
 htdocs/compta/bank/rappro.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/htdocs/compta/bank/rappro.php b/htdocs/compta/bank/rappro.php
index 2463c768098..d631e8e1843 100644
--- a/htdocs/compta/bank/rappro.php
+++ b/htdocs/compta/bank/rappro.php
@@ -84,7 +84,7 @@ if ($action == 'rappro' && $user->rights->banque->consolidate)
 
     if (! $error)
     {
-		header('Location: '.DOL_URL_ROOT.'/compta/bank/rappro?account='.$id);	// To avoid to submit twice and allow back
+		header('Location: '.DOL_URL_ROOT.'/compta/bank/rappro.php?account='.$id);	// To avoid to submit twice and allow back
     	exit;
     }
 }

From c3589e97856911e080a99fbcc98084091f99a449 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur 
Date: Sat, 23 Mar 2013 19:23:17 +0100
Subject: [PATCH 10/10] Some debug into cron module: - Because cron is a
 module, constant must start with CRON_. - Miscellanous fixes. - For external
 link to run jobs from url, we must forge url using conf file and not
 autodetect url.

---
 htdocs/core/class/html.formcron.class.php     |  16 +-
 htdocs/core/lib/cron.lib.php                  |  25 +--
 htdocs/core/modules/modCron.class.php         |  16 +-
 htdocs/cron/admin/cron.php                    |  79 +++++----
 htdocs/cron/card.php                          | 142 ++++++++-------
 htdocs/cron/class/cronjob.class.php           | 162 +++++++++---------
 htdocs/langs/fr_FR/cron.lang                  |   4 +-
 htdocs/public/cron/cron_run_jobs.php          |  12 +-
 .../eldy/img/{menus => }/object_cron.png      | Bin
 scripts/cron/cron_run_jobs.php                | 102 ++++++-----
 10 files changed, 297 insertions(+), 261 deletions(-)
 rename htdocs/theme/eldy/img/{menus => }/object_cron.png (100%)
 mode change 100644 => 100755 scripts/cron/cron_run_jobs.php

diff --git a/htdocs/core/class/html.formcron.class.php b/htdocs/core/class/html.formcron.class.php
index 2acb83e3f05..b6747e04a56 100644
--- a/htdocs/core/class/html.formcron.class.php
+++ b/htdocs/core/class/html.formcron.class.php
@@ -41,7 +41,7 @@ class FormCron extends Form
 		return 1;
 	}
 
-	
+
 	/**
 	 * Display On Off selector
 	 *
@@ -53,7 +53,7 @@ class FormCron extends Form
 	function select_typejob($htmlname,$selected=0,$readonly=0)
 	{
 		global $langs;
-		
+
 		$langs->load('cron@cron');
 		if (!empty($readonly)) {
 			if ($selected=='command') {
@@ -68,26 +68,26 @@ class FormCron extends Form
 				$out.='';
 			}
 		}else {
-		
-		$out='';
+
 		if ($selected=='command') {
 			$selected_attr=' selected=\"selected\" ';
 		} else {
 			$selected_attr='';
 		}
 		$out.= '';
-		
+
 		if ($selected=='method') {
 			$selected_attr=' selected=\"selected\" ';
 		} else {
 			$selected_attr='';
 		}
 		$out.= '';
-		
+
 		$out.='';
 		}
-		
+
 		return $out;
 	}
 }
diff --git a/htdocs/core/lib/cron.lib.php b/htdocs/core/lib/cron.lib.php
index abd85131e29..7ba1e7b38a3 100644
--- a/htdocs/core/lib/cron.lib.php
+++ b/htdocs/core/lib/cron.lib.php
@@ -15,19 +15,18 @@
  * You should have received a copy of the GNU General Public License
  * along with this program. If not, see .
  */
+
 /**
  *	\file       cron/lib/cron.lib.php
- *	\brief      Ensemble de fonctions de base pour le module jobs
- *	\ingroup    jobs
+ *	\brief      Function for module cron
+ *	\ingroup    cron
  */
 
 /**
- * Return array of tabs to used on pages for third parties cards.
+ * Return array of tabs to used on pages to setup cron module.
  *
- * @param 	Object	$object		Object company shown
  * @return 	array				Array of tabs
  */
-
 function cronadmin_prepare_head()
 {
     global $langs, $conf, $user;
@@ -35,18 +34,24 @@ function cronadmin_prepare_head()
     $head = array();
 
     $head[$h][0] = dol_buildpath('/cron/admin/cron.php', 1);
-    $head[$h][1] = $langs->trans("CronSetup");
+    $head[$h][1] = $langs->trans("Miscellanous");
     $head[$h][2] = 'setup';
     $h++;
-    
+
     complete_head_from_modules($conf, $langs, $object, $head, $h, 'cronadmin');
-    
+
     complete_head_from_modules($conf, $langs, $object, $head, $h, 'cronadmin', 'remove');
-    
+
 
     return $head;
 }
 
+/**
+ * Return array of tabs to used on a cron job
+ *
+ * @param 	Object	$object		Object cron
+ * @return 	array				Array of tabs
+ */
 function cron_prepare_head($object)
 {
 	global $langs, $conf, $user;
@@ -59,7 +64,7 @@ function cron_prepare_head($object)
 	$h++;
 
 	$head[$h][0] = dol_buildpath('/cron/info.php', 1).'?id='.$object->id;
-	$head[$h][1] = $langs->trans("CronInfoPage");
+	$head[$h][1] = $langs->trans("Info");
 	$head[$h][2] = 'info';
 	$h++;
 
diff --git a/htdocs/core/modules/modCron.class.php b/htdocs/core/modules/modCron.class.php
index 53d9afabf30..828e3c2664a 100644
--- a/htdocs/core/modules/modCron.class.php
+++ b/htdocs/core/modules/modCron.class.php
@@ -43,7 +43,7 @@ class modCron extends DolibarrModules
 
 		// Family can be 'crm','financial','hr','projects','products','ecm','technic','other'
 		// It is used to group modules in module setup page
-        $this->family = "technic";
+        $this->family = "base";
         // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
         $this->name = preg_replace('/^mod/i','',get_class($this));
         $this->description = "Enable the Dolibarr cron service";
@@ -70,9 +70,9 @@ class modCron extends DolibarrModules
 
         // Constantes
         //-----------
-        	$this->const = array(	
+        	$this->const = array(
 				0=>array(
-					'MAIN_CRON_KEY',
+					'CRON_KEY',
 					'chaine',
 					'',
 					'CRON KEY',
@@ -93,25 +93,25 @@ class modCron extends DolibarrModules
 		$this->rights = array();		// Permission array used by this module
 		$this->rights_class = 'cron';
 		$r=0;
-		
+
 		$this->rights[$r][0] = 23001;
 		$this->rights[$r][1] = 'Read cron jobs';
 		$this->rights[$r][3] = 1;
 		$this->rights[$r][4] = 'read';
 		$r++;
-		
+
 		$this->rights[$r][0] = 23002;
 		$this->rights[$r][1] = 'Create cron Jobs';
 		$this->rights[$r][3] = 0;
 		$this->rights[$r][4] = 'create';
 		$r++;
-		
+
 		$this->rights[$r][0] = 23003;
 		$this->rights[$r][1] = 'Delete cron Jobs';
 		$this->rights[$r][3] = 0;
 		$this->rights[$r][4] = 'delete';
 		$r++;
-		
+
 		$this->rights[$r][0] = 23004;
 		$this->rights[$r][1] = 'Execute cron Jobs';
 		$this->rights[$r][3] = 0;
@@ -131,7 +131,7 @@ class modCron extends DolibarrModules
 						        'target'=>'',
 						        'user'=>2);				                // 0=Menu for internal users, 1=external users, 2=both
         $r++;
-        
+
         $this->menu[$r]=array(	'fk_menu'=>'fk_mainmenu=home,fk_leftmenu=modulesadmintools',		    // Use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode
 						        'type'=>'left',			                // This is a Left menu entry
 						        'titre'=>'CronListInactive',
diff --git a/htdocs/cron/admin/cron.php b/htdocs/cron/admin/cron.php
index 894e9dc4457..7846a25e636 100644
--- a/htdocs/cron/admin/cron.php
+++ b/htdocs/cron/admin/cron.php
@@ -1,28 +1,28 @@
 
  * Copyright (C) 2005-2013	Laurent Destailleur		
-* Copyright (C) 2011		Juanjo Menent			
-* Copyright (C) 2012		Regis Houssin			
-* Copyright (C) 2013		Florian Henry			
-*
-* 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 .
-*/
+ * Copyright (C) 2011		Juanjo Menent			
+ * Copyright (C) 2012		Regis Houssin			
+ * Copyright (C) 2013		Florian Henry			
+ *
+ * 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       cron/admin/cron.php
-*		\ingroup    cron
-*/
+ *		\ingroup    cron
+ */
 
 // Dolibarr environment
 $res = @include("../../main.inc.php"); // From htdocs directory
@@ -44,7 +44,7 @@ if (!empty($actionsave))
 
 	$db->begin();
 
-	$i+=dolibarr_set_const($db,'MAIN_CRON_KEY',trim(GETPOST("MAIN_CRON_KEY")),'chaine',0,'',0);
+	$i+=dolibarr_set_const($db,'CRON_KEY',trim(GETPOST("CRON_KEY")),'chaine',0,'',0);
 
 	if ($i >= 1)
 	{
@@ -61,7 +61,7 @@ if (!empty($actionsave))
 
 /*
  *	View
-*/
+ */
 
 llxHeader();
 
@@ -70,6 +70,7 @@ print_fiche_titre($langs->trans("CronSetup"),$linkback,'setup');
 
 // Configuration header
 $head = cronadmin_prepare_head();
+
 dol_fiche_head($head,'setup',$langs->trans("Module2300Name"),0,'cron');
 
 print "
\n"; @@ -86,7 +87,7 @@ print ""; print '
'; print ''; -print ''; @@ -101,38 +102,42 @@ print ''; print ''; +dol_fiche_end(); + print '

'; +// Define $urlwithroot +$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); +$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file +//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current + // Cron launch print ''.$langs->trans("URLToLaunchCronJobs").':
'; -$url=dol_buildpath('/public/cron/cron_run_jobs.php',1).(empty($conf->global->MAIN_CRON_KEY)?'':'?securitykey='.$conf->global->MAIN_CRON_KEY.'&').'userlogin='.$user->login; +$url=$urlwithroot.'/public/cron/cron_run_jobs.php'.(empty($conf->global->CRON_KEY)?'':'?securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login; print img_picto('','object_globe.png').' '.$url."
\n"; print ' '.$langs->trans("OrToLaunchASpecificJob").'
'; -$url=dol_buildpath('/public/cron/cron_run_jobs.php',1).(empty($conf->global->MAIN_CRON_KEY)?'':'?securitykey='.$conf->global->MAIN_CRON_KEY.'&').'userlogin='.$user->login.'&id=cronjobid'; +$url=$urlwithroot.'/public/cron/cron_run_jobs.php'.(empty($conf->global->CRON_KEY)?'':'?securitykey='.$conf->global->CRON_KEY.'&').'userlogin='.$user->login.'&id=cronjobid'; print img_picto('','object_globe.png').' '.$url."
\n"; print '
'; -print '
'; $linuxlike=1; if (preg_match('/^win/i',PHP_OS)) $linuxlike=0; if (preg_match('/^mac/i',PHP_OS)) $linuxlike=0; -if ($linuxlike) { - print $langs->trans("CronExplainHowToRunUnix"); -} else { - print $langs->trans("CronExplainHowToRunWin"); -} print '
'; print ''.$langs->trans("FileToLaunchCronJobs").':
'; -$file='/scripts/cron/cron_run_jobs.php'.' '.(empty($conf->global->MAIN_CRON_KEY)?'securitykey':''.$conf->global->MAIN_CRON_KEY.'').' '.$user->login.' cronjobid(optionnal)'; -if ($linuxlike) { - print 'user@host:'.DOL_DOCUMENT_ROOT.'$ php ..'.$file."
\n"; -} else { - print DOL_DOCUMENT_ROOT.'> php ..'.$file."
\n"; -} + +$file='/scripts/cron/cron_run_jobs.php'.' '.(empty($conf->global->CRON_KEY)?'securitykey':''.$conf->global->CRON_KEY.'').' '.$user->login.' [cronjobid]'; +print '
\n"; print '
'; +print $langs->trans("Note").': '; +if ($linuxlike) { + print $langs->trans("CronExplainHowToRunUnix"); +} else { + print $langs->trans("CronExplainHowToRunWin"); +} @@ -149,7 +154,7 @@ if (! empty($conf->use_javascript_ajax)) generic: true }, function(token) { - $("#MAIN_CRON_KEY").val(token); + $("#CRON_KEY").val(token); }); }); });'; diff --git a/htdocs/cron/card.php b/htdocs/cron/card.php index bd6ffb0e5c9..feb86585181 100644 --- a/htdocs/cron/card.php +++ b/htdocs/cron/card.php @@ -42,6 +42,11 @@ $action=GETPOST('action','alpha'); $confirm=GETPOST('confirm','alpha'); $cancel=GETPOST('cancel'); + +/* + * Actions + */ + $object = new Cronjob($db); if (!empty($id)) { $result=$object->fetch($id); @@ -56,13 +61,13 @@ if(!empty($cancel)) { }else { Header ( "Location: ".dol_buildpath('/cron/cron/list.php',1).'?status=1'); } - + } // Delete jobs if ($action == 'confirm_delete' && $confirm == "yes" && $user->rights->cron->delete){ - + $result = $object->delete($user); if ($result < 0) { @@ -105,7 +110,7 @@ if ($action=='add') { $object->dateend=dol_mktime(GETPOST('dateendhour','int'), GETPOST('dateendmin','int'), 0, GETPOST('dateendmonth','int'), GETPOST('dateendday','int'), GETPOST('dateendyear','int')); $object->unitfrequency=GETPOST('unitfrequency','int'); $object->frequency=$object->unitfrequency * GETPOST('nbfrequency','int'); - + //Ajout de la tache cron $result = $object->create($user); @@ -138,7 +143,7 @@ if ($action=='update') { $object->dateend=dol_mktime(GETPOST('dateendhour','int'), GETPOST('dateendmin','int'), 0, GETPOST('dateendmonth','int'), GETPOST('dateendday','int'), GETPOST('dateendyear','int')); $object->unitfrequency=GETPOST('unitfrequency','int'); $object->frequency=$object->unitfrequency * GETPOST('nbfrequency','int'); - + //Ajout de la tache cron $result = $object->update($user); @@ -187,16 +192,23 @@ if ($action=='inactive') { } -/* - * View -*/ +/* + * View + */ + +$form = new Form($db); +$formCron = new FormCron($db); + llxHeader('',$langs->trans("CronAdd")); -if ($action=='edit' || empty($action) || $action=='delete' || $action=='execute') { +if ($action=='edit' || empty($action) || $action=='delete' || $action=='execute') +{ $head=cron_prepare_head($object); dol_fiche_head($head, 'card', $langs->trans("CronTask"), 0, 'bill'); -} elseif ($action=='create') { +} +elseif ($action=='create') +{ print_fiche_titre($langs->trans("CronTask"),'','setup'); } @@ -223,9 +235,6 @@ if ($conf->use_javascript_ajax) print ''."\n"; } -$form = new Form($db); -$formCron = new FormCron($db); - if ($action == 'delete') { $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CronDelete"),$langs->trans("CronConfirmDelete"),"confirm_delete",'','',1); @@ -243,33 +252,37 @@ if ($action == 'execute'){ /* * Create Template -*/ + */ -if (empty($object->status)) { +if (empty($object->status) && $action != 'create') +{ dol_htmloutput_mesg($langs->trans("CronTaskInactive"),'','warning',1); } if (($action=="create") || ($action=="edit")) { - + print ''; print ''."\n"; - if (!empty($object->id)) { + if (!empty($object->id)) + { print ''."\n"; print ''."\n"; - } else { + } + else + { print ''."\n"; } - + print '
'.$langs->transcountry("AmountLT1",$mysoc->country_code).''.price($object->total_localtax1,1,'',1,-1,-1,$conf->currency).'
'.$langs->transcountry("AmountLT2",$mysoc->country_code).''.price($object->total_localtax2,1,'',1,-1,-1,$conf->currency).'
'.$langs->trans('AmountTTC').''.price($object->total_ttc,1,'',1,-1,-1,$conf->currency).'
'; print ''; print ''; print '
'.$langs->trans("KeyForCronAccess").''; +print ''; if (! empty($conf->use_javascript_ajax)) print ' '.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_token" class="linkobject"'); print '
'; print '"; - print ""; print ""; print "\n"; - + print ""; print "\n"; - + print ""; print "\n"; - + print ""; $priority=0; @@ -315,10 +328,10 @@ if (($action=="create") || ($action=="edit")) { print ""; print "\n"; - + print ""; - print ""; print "\n"; - - + print '"; print ""; print ""; print ""; print ""; print ""; print "\n"; - + print '"; print ""; print "\n"; - + print '"; print "\n"; - + print '"; print "\n"; - + print '
'; print $langs->trans('CronLabel')."label."\" /> "; + print "label."\" /> "; print ""; print "
"; print $langs->trans('CronType').""; print $formCron->select_typejob('jobtype',$object->jobtype); @@ -290,7 +303,7 @@ if (($action=="create") || ($action=="edit")) { print ""; print "
"; print $langs->trans('CronDtEnd').""; if(!empty($object->dateend)){ @@ -303,7 +316,7 @@ if (($action=="create") || ($action=="edit")) { print ""; print "
"; print $langs->trans('CronPriority').""; print "
"; print $langs->trans('CronEvery')."unitfrequency=="60"){ $input .= ' checked="checked" />'; } @@ -337,7 +350,7 @@ if (($action=="create") || ($action=="edit")) { $input .= ""; print $input; - $input = "unitfrequency=="3600"){ $input .= ' checked="checked" />'; } @@ -347,7 +360,7 @@ if (($action=="create") || ($action=="edit")) { $input .= ""; print $input; - $input = "unitfrequency=="86400"){ $input .= ' checked="checked" />'; } @@ -370,11 +383,10 @@ if (($action=="create") || ($action=="edit")) { print ""; print "
'; print $langs->trans('CronModule').""; - print "module_name."\" /> "; + print "module_name."\" /> "; print ""; print $form->textwithpicto('',$langs->trans("CronModuleHelp"),1,'help'); @@ -383,7 +395,7 @@ if (($action=="create") || ($action=="edit")) { print '
'; print $langs->trans('CronClassFile').""; - print "classesname."\" /> "; + print "classesname."\" /> "; print ""; print $form->textwithpicto('',$langs->trans("CronClassFileHelp"),1,'help'); @@ -392,7 +404,7 @@ if (($action=="create") || ($action=="edit")) { print '
'; print $langs->trans('CronObject').""; - print "objectname."\" /> "; + print "objectname."\" /> "; print ""; print $form->textwithpicto('',$langs->trans("CronObjectHelp"),1,'help'); @@ -401,7 +413,7 @@ if (($action=="create") || ($action=="edit")) { print '
'; print $langs->trans('CronMethod').""; - print "methodename."\" /> "; + print "methodename."\" /> "; print ""; print $form->textwithpicto('',$langs->trans("CronMethodHelp"),1,'help'); @@ -410,22 +422,22 @@ if (($action=="create") || ($action=="edit")) { print '
'; print $langs->trans('CronArgs').""; - print "params."\" /> "; + print "params."\" /> "; print ""; print $form->textwithpicto('',$langs->trans("CronArgsHelp"),1,'help'); print "
'; print $langs->trans('CronCommand').""; - print "command."\" /> "; + print "command."\" /> "; print ""; print $form->textwithpicto('',$langs->trans("CronCommandHelp"),1,'help'); print "
'; print $langs->trans('CronNote').""; $doleditor = new DolEditor('note', $object->note, '', 160, 'dolibarr_notes', 'In', true, false, 0, 4, 90); @@ -435,7 +447,7 @@ if (($action=="create") || ($action=="edit")) { print "
'; print "trans("Save")."\">"; print "trans("Cancel")."\">"; @@ -443,20 +455,22 @@ if (($action=="create") || ($action=="edit")) { print ""; print "
'; - + print "\n"; - -}else { - + +} +else +{ + /* * view Template - */ - + */ + // box add_jobs_box print ''; - + print '"; print ""; print ""; - + print ""; - + print ""; - + print ""; print ""; - + print ""; print ""; - + print ""; print ""; - - + + print '"; - + print '"; - + print '"; - + print '"; - + print '"; - + print '"; - + print '"; - + print '"; print '
'; print $langs->trans('CronId')."".$form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'id'); @@ -466,7 +480,7 @@ if (($action=="create") || ($action=="edit")) { print $langs->trans('CronLabel')."".$object->label; print "
"; print $langs->trans('CronType').""; print $formCron->select_typejob('jobtype',$object->jobtype,1); @@ -476,32 +490,32 @@ if (($action=="create") || ($action=="edit")) { print $langs->trans('CronHourStart').""; if(!empty($object->datestart)) {print dol_print_date($object->datestart,'dayhourtext');} else {print $langs->trans('CronNone');} print "
"; print $langs->trans('CronDtEnd').""; if(!empty($object->dateend)) {print dol_print_date($object->dateend,'dayhourtext');} else {print $langs->trans('CronNone');} print "
"; print $langs->trans('CronPriority')."".$object->priority; print "
"; print $langs->trans('CronNbRun')."".$object->nbrun; print "
"; print $langs->trans('CronEvery').""; if($object->unitfrequency == "60") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Minutes'); if($object->unitfrequency == "3600") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Hours'); if($object->unitfrequency == "86400") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Days'); - if($object->unitfrequency == "604800") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Weeks'); + if($object->unitfrequency == "604800") print $langs->trans('CronEach')." ".($object->frequency/$object->unitfrequency)." ".$langs->trans('Weeks'); print "
'; print $langs->trans('CronModule').""; print $object->module_name; @@ -526,44 +540,48 @@ if (($action=="create") || ($action=="edit")) { print $langs->trans('CronArgs').""; print $object->params; print "
'; print $langs->trans('CronCommand').""; print $object->command; print "
'; print $langs->trans('CronNote').""; print $object->note; print "
'; print $langs->trans('CronDtLastLaunch').""; if(!empty($object->datelastrun)) {print dol_print_date($object->datelastrun,'dayhourtext');} else {print $langs->trans('CronNone');} print "
'; print $langs->trans('CronDtNextLaunch').""; if(!empty($object->datenextrun)) {print dol_print_date($object->datenextrun,'dayhourtext');} else {print $langs->trans('CronNone');} print "
'; print $langs->trans('CronDtLastResult').""; if(!empty($object->datelastresult)) {print dol_print_date($object->datelastresult,'dayhourtext');} else {print $langs->trans('CronNone');} print "
'; print $langs->trans('CronLastResult').""; print $object->lastresult; print "
'; print $langs->trans('CronLastOutput').""; print nl2br($object->lastoutput); print "
'; - + + + print dol_fiche_end(); + + print "\n\n
\n"; if (! $user->rights->cron->create) { print ''.$langs->trans("Edit").''; diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index b24055c6f3d..ebc6c4952e3 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -37,7 +37,7 @@ class Cronjob extends CommonObject var $table_element='cronjob'; //!< Name of table without prefix where object is stored var $id; - + var $ref; //Use for prevnext_ref var $jobtype; var $tms=''; @@ -65,10 +65,10 @@ class Cronjob extends CommonObject var $fk_user_mod; var $note; var $nbrun; - + var $lines; - + /** @@ -96,7 +96,7 @@ class Cronjob extends CommonObject $error=0; // Clean parameters - + if (isset($this->label)) $this->label=trim($this->label); if (isset($this->jobtype)) $this->jobtype=trim($this->jobtype); if (isset($this->command)) $this->command=trim($this->command); @@ -152,7 +152,7 @@ class Cronjob extends CommonObject // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."cronjob("; - + $sql.= "datec,"; $sql.= "jobtype,"; $sql.= "label,"; @@ -179,9 +179,9 @@ class Cronjob extends CommonObject $sql.= "note,"; $sql.= "nbrun"; - + $sql.= ") VALUES ("; - + $sql.= " ".$this->db->idate(dol_now()).","; $sql.= " ".(! isset($this->jobtype)?'NULL':"'".$this->db->escape($this->jobtype)."'").","; $sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").","; @@ -208,16 +208,16 @@ class Cronjob extends CommonObject $sql.= " ".(! isset($this->note)?'NULL':"'".$this->db->escape($this->note)."'").","; $sql.= " ".(! isset($this->nbrun)?'0':"'".$this->db->escape($this->nbrun)."'").""; - + $sql.= ")"; - + $this->db->begin(); dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - + if (! $error) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."cronjob"); @@ -266,7 +266,7 @@ class Cronjob extends CommonObject global $langs; $sql = "SELECT"; $sql.= " t.rowid,"; - + $sql.= " t.tms,"; $sql.= " t.datec,"; $sql.= " t.jobtype,"; @@ -294,7 +294,7 @@ class Cronjob extends CommonObject $sql.= " t.note,"; $sql.= " t.nbrun"; - + $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t"; $sql.= " WHERE t.rowid = ".$id; @@ -308,7 +308,7 @@ class Cronjob extends CommonObject $this->id = $obj->rowid; $this->ref = $obj->rowid; - + $this->tms = $this->db->jdate($obj->tms); $this->datec = $this->db->jdate($obj->datec); $this->label = $obj->label; @@ -336,7 +336,7 @@ class Cronjob extends CommonObject $this->note = $obj->note; $this->nbrun = $obj->nbrun; - + } $this->db->free($resql); @@ -349,7 +349,7 @@ class Cronjob extends CommonObject return -1; } } - + /** * Load object in memory from the database * @@ -392,8 +392,8 @@ class Cronjob extends CommonObject $sql.= " t.fk_user_mod,"; $sql.= " t.note,"; $sql.= " t.nbrun"; - - + + $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as t"; $status = (empty($status))?'0':'1'; $sql.= " WHERE t.status=".$status; @@ -403,43 +403,43 @@ class Cronjob extends CommonObject $sql.= ' AND '.$key.' LIKE \'%'.$value.'%\''; } } - - - $sql.= " ORDER BY $sortfield $sortorder "; + + + $sql.= " ORDER BY $sortfield $sortorder "; if (!empty($limit) && !empty($offset)) { $sql.= $this->db->plimit( $limit + 1 ,$offset); } - + $sqlwhere = array(); - + if (!empty($module_name)) { $sqlwhere[]='(t.module_name='.$module_name.')'; } if (count($sqlwhere)>0) { $sql.= " WHERE ".implode(' AND ',$sqlwhere); } - + dol_syslog(get_class($this)."::fetch_all sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { $num=$this->db->num_rows($resql); $i=0; - + if ($num) { $this->lines=array(); - + while ($i < $num) { - + $line = new Cronjobline(); - + $obj = $this->db->fetch_object($resql); - + $line->id = $obj->rowid; $line->ref = $obj->rowid; - + $line->tms = $this->db->jdate($obj->tms); $line->datec = $this->db->jdate($obj->datec); $line->label = $obj->label; @@ -466,15 +466,15 @@ class Cronjob extends CommonObject $line->fk_user_mod = $obj->fk_user_mod; $line->note = $obj->note; $line->nbrun = $obj->nbrun; - + $this->lines[]=$line; - + $i++; - + } } $this->db->free($resql); - + return 1; } else @@ -496,13 +496,13 @@ class Cronjob extends CommonObject function update($user=0, $notrigger=0) { global $conf, $langs; - + $langs->load('cron'); - + $error=0; // Clean parameters - + if (isset($this->label)) $this->label=trim($this->label); if (isset($this->jobtype)) $this->jobtype=trim($this->jobtype); if (isset($this->command)) $this->command=trim($this->command); @@ -558,11 +558,11 @@ class Cronjob extends CommonObject $this->errors[]=$langs->trans('CronFieldMandatory',$langs->trans('CronObject')); $error++; } - + // Update request $sql = "UPDATE ".MAIN_DB_PREFIX."cronjob SET"; - + $sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").","; $sql.= " jobtype=".(isset($this->jobtype)?"'".$this->db->escape($this->jobtype)."'":"null").","; $sql.= " command=".(isset($this->command)?"'".$this->db->escape($this->command)."'":"null").","; @@ -587,7 +587,7 @@ class Cronjob extends CommonObject $sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").","; $sql.= " nbrun=".(isset($this->nbrun)?$this->nbrun:"null"); - + $sql.= " WHERE rowid=".$this->id; $this->db->begin(); @@ -595,7 +595,7 @@ class Cronjob extends CommonObject dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } - + if (! $error) { if (! $notrigger) @@ -755,7 +755,7 @@ class Cronjob extends CommonObject { $this->id=0; $this->ref=0; - + $this->tms=''; $this->datec=''; $this->label=''; @@ -780,24 +780,24 @@ class Cronjob extends CommonObject $this->status=''; $this->fk_user_author=''; $this->fk_user_mod=''; - $this->note=''; + $this->note=''; $this->nbrun=''; } - + /** - * Load object information + * Load object information * * @return void */ function info() { global $langs; - + $sql = "SELECT"; $sql.= " f.rowid, f.datec, f.tms, f.fk_user_mod, f.fk_user_author"; $sql.= " FROM ".MAIN_DB_PREFIX."cronjob as f"; $sql.= " WHERE f.rowid = ".$this->id; - + dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) @@ -812,7 +812,7 @@ class Cronjob extends CommonObject $this->user_creation = $obj->fk_user_author; } $this->db->free($resql); - + return 1; } else @@ -822,26 +822,26 @@ class Cronjob extends CommonObject return -1; } } - + /** * Run a job - * + * * @param string $userlogin User login * @return int <0 if KO, >0 if OK */ function run_jobs($userlogin) { global $langs, $conf; - + $langs->load('cron'); - + if (empty($userlogin)) { $this->error="User login is mandatory"; dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); return -1; } - + require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; $user=new User($this->db); $result=$user->fetch('',$userlogin); @@ -856,14 +856,14 @@ class Cronjob extends CommonObject return -1; } } - + dol_syslog(get_class($this)."::run_jobs userlogin:$userlogin", LOG_DEBUG); - + $error=0; $now=dol_now(); - + $this->db->begin(); - + if ($this->jobtype=='method') { // load classes $ret=dol_include_once("/".$this->module_name."/class/".$this->classesname,$this->objectname); @@ -872,19 +872,19 @@ class Cronjob extends CommonObject dol_syslog(get_class($this)."::run_jobs ".$this->error, LOG_ERR); return -1; } - + // Load langs $result=$langs->load($this->module_name.'@'.$this->module_name); if ($result<0) { dol_syslog(get_class($this)."::run_jobs Cannot load module langs".$langs->error, LOG_ERR); return -1; } - + dol_syslog(get_class($this)."::run_jobs ".$this->objectname."->".$this->methodename."(".$this->params.");", LOG_DEBUG); - + // Create Object for the call module $object = new $this->objectname($this->db); - + $params_arr = array(); $params_arr=explode(", ",$this->params); if (!is_array($params_arr)) { @@ -892,7 +892,7 @@ class Cronjob extends CommonObject }else { $result = call_user_func_array(array($object, $this->methodename), $params_arr); } - + if ($result===false) { dol_syslog(get_class($this)."::run_jobs ".$object->error, LOG_ERR); return -1; @@ -900,15 +900,15 @@ class Cronjob extends CommonObject $this->lastoutput=var_export($result,true); $this->lastresult=var_export($result,true); } - + } elseif ($this->jobtype=='command') { dol_syslog(get_class($this)."::run_jobs system:".$this->command, LOG_DEBUG); $output_arr=array(); - + exec($this->command, $output_arr,$retval); - + dol_syslog(get_class($this)."::run_jobs output_arr:".var_export($output_arr,true), LOG_DEBUG); - + $this->lastoutput=''; if (is_array($output_arr) && count($output_arr)>0) { foreach($output_arr as $val) { @@ -917,7 +917,7 @@ class Cronjob extends CommonObject } $this->lastresult=$retval; } - + $this->datelastresult=$now; $this->datelastrun=$now; $this->nbrun=$this->nbrun+1; @@ -930,23 +930,23 @@ class Cronjob extends CommonObject $this->db->commit(); return 1; } - - + + } - + /** * Reprogram a job * * @param string $userlogin User login - * @return int <0 if KO, >0 if OK - * + * @return int <0 if KO, >0 if OK + * */ function reprogram_jobs($userlogin) { global $langs, $conf; - + dol_syslog(get_class($this)."::reprogram_jobs userlogin:$userlogin", LOG_DEBUG); - + require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; $user=new User($this->db); $result=$user->fetch('',$userlogin); @@ -961,9 +961,9 @@ class Cronjob extends CommonObject return -1; } } - + dol_syslog(get_class($this)."::reprogram_jobs ", LOG_DEBUG); - + if (empty($this->datenextrun)) { $this->datenextrun=dol_now()+$this->frequency; } else { @@ -972,15 +972,15 @@ class Cronjob extends CommonObject } else { $this->datenextrun=$this->datenextrun+$this->frequency; } - } + } $result = $this->update($user); if ($result<0) { dol_syslog(get_class($this)."::reprogram_jobs ".$this->error, LOG_ERR); return -1; } - + return 1; - + } } @@ -989,10 +989,10 @@ class Cronjob extends CommonObject * Crob Job line class */ class Cronjobline{ - + var $id; var $ref; - + var $tms=''; var $datec=''; var $label; @@ -1018,7 +1018,7 @@ class Cronjobline{ var $fk_user_mod; var $note; var $nbrun; - + /** * Constructor * diff --git a/htdocs/langs/fr_FR/cron.lang b/htdocs/langs/fr_FR/cron.lang index d0aaccfecf7..b5fa47b336a 100644 --- a/htdocs/langs/fr_FR/cron.lang +++ b/htdocs/langs/fr_FR/cron.lang @@ -9,8 +9,8 @@ URLToLaunchCronJobs=URL pour lancer les taches automatiques OrToLaunchASpecificJob=Ou pour lancer une tache spécifique KeyForCronAccess=Clé de sécurité pour l'URL de lancement des taches automatiques FileToLaunchCronJobs=Commande pour lancer les taches automatiques -CronExplainHowToRunUnix=Sur un environement Unix vous pouvez paramétré CronTab pour executer cette commande toute les minutes -CronExplainHowToRunWin=Sur un environement Microsoft(tm) Windows vous pouvez utilisr le planificateur de tache pour lancer cette commande toute les minutes +CronExplainHowToRunUnix=Sur un environement Unix vous pouvez paramétrer CronTab pour executer cette commande toute les minutes. +CronExplainHowToRunWin=Sur un environement Microsoft(tm) Windows vous pouvez utiliser le planificateur de tache pour lancer cette commande toute les minutes. # # Menu diff --git a/htdocs/public/cron/cron_run_jobs.php b/htdocs/public/cron/cron_run_jobs.php index 838c298212f..7f25cfaf63c 100644 --- a/htdocs/public/cron/cron_run_jobs.php +++ b/htdocs/public/cron/cron_run_jobs.php @@ -49,7 +49,7 @@ if (empty($key)) { echo 'securitykey is require'; exit; } -if($key != $conf->global->MAIN_CRON_KEY) +if($key != $conf->global->CRON_KEY) { echo 'securitykey is wrong'; exit; @@ -104,13 +104,13 @@ if(is_array($object->lines) && (count($object->lines)>0)){ foreach($object->lines as $line){ dol_syslog("cron_run_jobs.php:: fetch cronjobid:".$line->id, LOG_ERR); - + //If date_next_jobs is less of current dat, execute the program, and store the execution time of the next execution in database if ((($line->datenextrun <= $now) && $line->dateend < $now) || ((empty($line->datenextrun)) && (empty($line->dateend)))){ - + dol_syslog("cron_run_jobs.php:: torun line->datenextrun:".dol_print_date($line->datenextrun,'dayhourtext')." line->dateend:".dol_print_date($line->dateend,'dayhourtext')." now:".dol_print_date($now,'dayhourtext'), LOG_ERR); - + $cronjob=new Cronjob($db); $result=$cronjob->fetch($line->id); if ($result<0) { @@ -125,7 +125,7 @@ if(is_array($object->lines) && (count($object->lines)>0)){ dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR); exit; } - + // we re-program the next execution and stores the last execution time for this job $result=$cronjob->reprogram_jobs($userlogin); if ($result<0) { @@ -133,7 +133,7 @@ if(is_array($object->lines) && (count($object->lines)>0)){ dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR); exit; } - + } } echo "OK"; diff --git a/htdocs/theme/eldy/img/menus/object_cron.png b/htdocs/theme/eldy/img/object_cron.png similarity index 100% rename from htdocs/theme/eldy/img/menus/object_cron.png rename to htdocs/theme/eldy/img/object_cron.png diff --git a/scripts/cron/cron_run_jobs.php b/scripts/cron/cron_run_jobs.php old mode 100644 new mode 100755 index 0c22107bde6..159fadd3a61 --- a/scripts/cron/cron_run_jobs.php +++ b/scripts/cron/cron_run_jobs.php @@ -27,72 +27,74 @@ if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); -if (! defined('NOLOGIN')) define('NOLOGIN','1'); +if (! defined('NOLOGIN')) define('NOLOGIN','1'); //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); -$sapi_type = php_sapi_name(); -$script_file = basename(__FILE__); -$path=dirname(__FILE__).'/'; - -// Test if batch mode -if (substr($sapi_type, 0, 3) == 'cgi') { - echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; - exit; -} +$sapi_type = php_sapi_name(); +$script_file = basename(__FILE__); +$path=dirname(__FILE__).'/'; + +// Test if batch mode +if (substr($sapi_type, 0, 3) == 'cgi') { + echo "Error: You are using PHP for CGI. To execute ".$script_file." from command line, you must use PHP for CLI mode.\n"; + exit; +} + if (! isset($argv[1]) || ! $argv[1]) { print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n"; exit; } -$key=$argv[1]; +$key=$argv[1]; -if (! isset($argv[2]) || ! $argv[2]) { - print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n"; - exit; -} else { - $userlogin=$argv[2]; -} +if (! isset($argv[2]) || ! $argv[2]) { + print "Usage: ".$script_file." securitykey userlogin cronjobid(optional)\n"; + exit; +} else { + $userlogin=$argv[2]; +} + +require_once ($path."../../htdocs/master.inc.php"); +require_once (DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php"); +require_once (DOL_DOCUMENT_ROOT.'/user/class/user.class.php'); +require_once (DOL_DOCUMENT_ROOT."/cron/class/cronjob.class.php"); -$res=@include("../../master.inc.php"); // For root directory -if (! $res) $res=@include("../../../master.inc.php"); // For "custom" directory -if (! $res) die("Include of master.inc.php fails"); +/* + * Main + */ - -// librarie jobs -require_once (DOL_DOCUMENT_ROOT_ALT."/cron/class/cronjob.class.php"); - - -//Check security key -if($key != $conf->global->MAIN_CRON_KEY) +// Check security key +if ($key != $conf->global->CRON_KEY) { - echo 'securitykey is wrong'; + print "Error: securitykey is wrong\n"; exit; } -//Check user login -require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; +// Check user login $user=new User($db); $result=$user->fetch('',$userlogin); -if ($result<0) { - echo "User Error:".$user->error; +if ($result < 0) +{ + echo "User Error: ".$user->error; dol_syslog("cron_run_jobs.php:: User Error:".$user->error, LOG_ERR); exit; -}else { - if (empty($user->id)) { - echo " User user login:".$userlogin." do not exists"; +} +else +{ + if (empty($user->id)) + { + echo " User user login: ".$userlogin." do not exists"; dol_syslog(" User user login:".$userlogin." do not exists", LOG_ERR); exit; } } -if (isset($argv[3]) || $argv[3]) { +if (isset($argv[3]) || $argv[3]) +{ $id = $argv[3]; } -// librarie jobs -require_once (DOL_DOCUMENT_ROOT_ALT."/cron/class/cronjob.class.php"); - // create a jobs object $object = new Cronjob($db); @@ -103,18 +105,21 @@ if (empty($id)) { } $result = $object->fetch_all('DESC','t.rowid', 0, 0, 1, $filter); -if ($result<0) { - echo "Error:".$cronjob->error; - dol_syslog("cron_run_jobs.php:: fetch Error".$cronjob->error, LOG_ERR); +if ($result<0) +{ + echo "Error: ".$object->error; + dol_syslog("cron_run_jobs.php:: fetch Error ".$object->error, LOG_ERR); exit; } // current date $now=dol_now(); -if(is_array($object->lines) && (count($object->lines)>0)){ +if(is_array($object->lines) && (count($object->lines)>0)) +{ // Loop over job - foreach($object->lines as $line){ + foreach($object->lines as $line) + { //If date_next_jobs is less of current dat, execute the program, and store the execution time of the next execution in database if (($line->datenextrun < $now) && $line->dateend < $now){ @@ -132,7 +137,7 @@ if(is_array($object->lines) && (count($object->lines)>0)){ dol_syslog("cron_run_jobs.php:: run_jobs Error".$cronjob->error, LOG_ERR); exit; } - + // we re-program the next execution and stores the last execution time for this job $result=$cronjob->reprogram_jobs($userlogin); if ($result<0) { @@ -140,7 +145,10 @@ if(is_array($object->lines) && (count($object->lines)>0)){ dol_syslog("cron_run_jobs.php:: reprogram_jobs Error".$cronjob->error, LOG_ERR); exit; } - + } } -} \ No newline at end of file +} + +$db->close(); +?> \ No newline at end of file