';
$moreforfilter .= $langs->trans('Period') . ' ('.$langs->trans('DateOperationShort').') : ' . $langs->trans('StartDate') . ' ';
$moreforfilter .= $form->select_date($search_dt_start, 'search_start_dt', 0, 0, 1, "search_form", 1, 0, 1);
@@ -209,6 +215,7 @@ if ($resql)
print_liste_field_titre($langs->trans("Debit"),$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Credit"),$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("Account"),$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder);
+ print_liste_field_titre('');
print "\n";
print '
';
print '';
}
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 88be9bab0ba..2ce51ad3afd 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -2346,7 +2346,7 @@ if ($action == 'create')
{
print '
';
}
@@ -2361,7 +2361,7 @@ if ($action == 'create')
// Template to use by default
print '
';
}
@@ -3074,7 +3074,9 @@ else if ($id > 0 || ! empty($ref))
$nbrows ++;
if ($selleruserevenustamp)
$nbrows ++;
-
+ if (! empty($conf->multicurrency->enabled)) $nbrows+=5;
+ if (! empty($conf->incoterm->enabled)) $nbrows+=1;
+
print '
';
// Previous situation(s) deduction(s)
- for ($i = 0; $i < count($prevsits); $i++) {
+ for ($i = 0; $i < $cprevsits; $i++) {
print '
';
print '';
print $langs->trans('SituationDeduction');
@@ -3841,6 +3845,7 @@ else if ($id > 0 || ! empty($ref))
}
}
+ // deprecated. Useless because now we can use templates
if (! empty($conf->global->FACTURE_SHOW_SEND_REMINDER)) // For backward compatibility
{
if (($object->statut == 1 || $object->statut == 2) && $resteapayer > 0) {
@@ -3896,7 +3901,7 @@ else if ($id > 0 || ! empty($ref))
// Classify paid
if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement && (($object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT && $resteapayer <= 0) || ($object->type == Facture::TYPE_CREDIT_NOTE && $resteapayer >= 0))
- || ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 0 && $resteapayer == 0 && $user->rights->facture->paiement && empty($discount->id))
+ || ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 0 && $object->total_ttc > 0 && $resteapayer == 0 && $user->rights->facture->paiement && empty($discount->id))
)
{
print '';
@@ -3926,10 +3931,10 @@ else if ($id > 0 || ! empty($ref))
print '';
}
- // Clone as predefined
+ // Clone as predefined / Create template
if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $object->statut == 0 && $user->rights->facture->creer)
{
- if (! $objectidnext)
+ if (! $objectidnext && count($object->lines) > 0)
{
print '';
}
@@ -3944,7 +3949,7 @@ else if ($id > 0 || ! empty($ref))
}
}
- //Create next situation invoice
+ // Create next situation invoice
if ($user->rights->facture->creer && ($object->type == 5) && ($object->statut == 1 || $object->statut == 2)) {
if ($object->is_last_in_cycle() && $object->situation_final != 1) {
print '';
diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php
index f2ef90677c5..b0a7bab2899 100644
--- a/htdocs/compta/facture/class/facture-rec.class.php
+++ b/htdocs/compta/facture/class/facture-rec.class.php
@@ -30,6 +30,7 @@
require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
/**
@@ -83,7 +84,20 @@ class FactureRec extends Facture
// Clean parameters
$this->titre=trim($this->titre);
$this->usenewprice=empty($this->usenewprice)?0:$this->usenewprice;
-
+
+ // No frequency defined then no next date to execution
+ if (empty($this->frequency))
+ {
+ $this->frequency=0;
+ $this->date_when=NULL;
+ }
+
+
+ $this->frequency=abs($this->frequency);
+ $this->nb_gen_done=0;
+ $this->nb_gen_max=empty($this->nb_gen_max)?0:$this->nb_gen_max;
+ $this->auto_validate=empty($this->auto_validate)?0:$this->auto_validate;
+
$this->db->begin();
// Charge facture modele
@@ -105,9 +119,17 @@ class FactureRec extends Facture
$sql.= ", note_public";
$sql.= ", fk_user_author";
$sql.= ", fk_projet";
+ $sql.= ", fk_account";
$sql.= ", fk_cond_reglement";
$sql.= ", fk_mode_reglement";
$sql.= ", usenewprice";
+ $sql.= ", frequency";
+ $sql.= ", unit_frequency";
+ $sql.= ", date_when";
+ $sql.= ", date_last_gen";
+ $sql.= ", nb_gen_done";
+ $sql.= ", nb_gen_max";
+ $sql.= ", auto_validate";
$sql.= ") VALUES (";
$sql.= "'".$this->titre."'";
$sql.= ", ".$facsrc->socid;
@@ -119,9 +141,17 @@ class FactureRec extends Facture
$sql.= ", ".(!empty($this->note_public)?("'".$this->db->escape($this->note_public)."'"):"NULL");
$sql.= ", '".$user->id."'";
$sql.= ", ".(! empty($facsrc->fk_project)?"'".$facsrc->fk_project."'":"null");
+ $sql.= ", ".(! empty($facsrc->fk_account)?"'".$facsrc->fk_account."'":"null");
$sql.= ", '".$facsrc->cond_reglement_id."'";
$sql.= ", '".$facsrc->mode_reglement_id."'";
$sql.= ", ".$this->usenewprice;
+ $sql.= ", ".$this->frequency;
+ $sql.= ", '".$this->db->escape($this->unit_frequency)."'";
+ $sql.= ", ".(!empty($this->date_when)?"'".$this->db->idate($this->date_when)."'":'NULL');
+ $sql.= ", ".(!empty($this->date_last_gen)?"'".$this->db->idate($this->date_last_gen)."'":'NULL');
+ $sql.= ", ".$this->nb_gen_done;
+ $sql.= ", ".$this->nb_gen_max;
+ $sql.= ", ".$this->auto_validate;
$sql.= ")";
if ($this->db->query($sql))
@@ -197,7 +227,9 @@ class FactureRec extends Facture
$sql = 'SELECT f.titre,f.fk_soc,f.amount,f.tva,f.total,f.total_ttc,f.remise_percent,f.remise_absolue,f.remise';
$sql.= ', f.date_lim_reglement as dlr';
$sql.= ', f.note_private, f.note_public, f.fk_user_author';
- $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement';
+ $sql.= ', f.fk_mode_reglement, f.fk_cond_reglement, f.fk_projet';
+ $sql.= ', f.fk_account';
+ $sql.= ', f.frequency, f.unit_frequency, f.date_when, f.date_last_gen, f.nb_gen_done, f.nb_gen_max, f.usenewprice, f.auto_validate';
$sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
$sql.= ', c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_doc';
$sql.= ', el.fk_source';
@@ -248,6 +280,7 @@ class FactureRec extends Facture
$this->cond_reglement = $obj->cond_reglement_libelle;
$this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
$this->fk_project = $obj->fk_projet;
+ $this->fk_account = $obj->fk_account;
$this->fk_facture_source = $obj->fk_facture_source;
$this->note_private = $obj->note_private;
$this->note_public = $obj->note_public;
@@ -255,6 +288,14 @@ class FactureRec extends Facture
$this->modelpdf = $obj->model_pdf;
$this->rang = $obj->rang;
$this->special_code = $obj->special_code;
+ $this->frequency = $obj->frequency;
+ $this->unit_frequency = $obj->unit_frequency;
+ $this->date_when = $obj->date_when;
+ $this->date_last_gen = $obj->date_last_gen;
+ $this->nb_gen_done = $obj->nb_gen_done;
+ $this->nb_gen_max = $obj->nb_gen_max;
+ $this->usenewprice = $obj->usenewprice;
+ $this->auto_validate = $obj->auto_validate;
if ($this->statut == self::STATUS_DRAFT) $this->brouillon = 1;
@@ -468,7 +509,7 @@ class FactureRec extends Facture
$total_ht = $tabprice[0];
$total_tva = $tabprice[1];
$total_ttc = $tabprice[2];
-
+
$product_type=$type;
if ($fk_product)
{
@@ -529,6 +570,63 @@ class FactureRec extends Facture
}
}
+ /**
+ * Return the next date of
+ *
+ * @return timestamp false if KO, timestamp if OK
+ */
+ function getNextDate()
+ {
+ if (empty($this->date_when)) return false;
+ return dol_time_plus_duree(strtotime($this->date_when), $this->frequency, $this->unit_frequency);
+ }
+
+ /**
+ * Create all recurrents invoices
+ *
+ * @return int number of created invoices
+ */
+ function createRecurringInvoices()
+ {
+ global $db,$user;
+
+ $nb_create=0;
+
+ $today = date('Y-m-d 23:59:59');
+
+ $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'facture_rec';
+ $sql.= ' WHERE date_when IS NOT NULL AND frequency > 0';
+ $sql.= ' AND date_when <= "'.$db->escape($today).'"';
+ $sql.= ' AND nb_gen_done < nb_gen_max';
+
+ $resql = $db->query($sql);
+ if ($resql)
+ {
+ while ($line = $db->fetch_object($resql))
+ {
+ $facturerec = new FactureRec($db);
+ $facturerec->fetch($line->rowid);
+
+ $facture = new Facture($db);
+ $result = $facture->createFromRec($user, $facturerec);
+
+ // >0 create and validate if auto_validate
+ // =0 create but not validate if auto_validate
+ // <0 broken
+ if ($result >= 0)
+ {
+ $next_date = $facturerec->getNextDate();
+ $facturerec->setNextDate($next_date,1);
+
+ $nb_create++;
+ }
+
+ }
+ }
+
+ return $nb_create;
+ }
+
/**
* Return clicable name (with picto eventually)
*
@@ -601,4 +699,143 @@ class FactureRec extends Facture
return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
}
+
+ /**
+ * Update frequency and unit
+ *
+ * @param int $frequency value of frequency
+ * @param string $unit unit of frequency (d, m, y)
+ * @return int <0 if KO, >0 if OK
+ */
+ function setFrequencyAndUnit($frequency,$unit)
+ {
+ if (! $this->table_element)
+ {
+ dol_syslog(get_class($this)."::setFrequencyAndUnit was called on objet with property table_element not defined",LOG_ERR);
+ return -1;
+ }
+
+ if (!empty($frequency) && empty($unit))
+ {
+ dol_syslog(get_class($this)."::setFrequencyAndUnit was called on objet with params frequency defined but unit not defined",LOG_ERR);
+ return -2;
+ }
+
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
+ $sql.= ' SET frequency = '.($frequency?$this->db->escape($frequency):'null');
+ if (!empty($unit))
+ {
+ $sql.= ', unit_frequency = "'.$this->db->escape($unit).'"';
+ }
+ $sql.= ' WHERE rowid = '.$this->id;
+
+ dol_syslog(get_class($this)."::setFrequencyAndUnit", LOG_DEBUG);
+ if ($this->db->query($sql))
+ {
+ $this->frequency = $frequency;
+ if (!empty($unit)) $this->unit_frequency = $unit;
+ return 1;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
+
+ /**
+ * Update the next date of execution
+ *
+ * @param datetime $date date of execution
+ * @param int $increment_nb_gen_done 0 do nothing more, >0 increment nb_gen_done
+ * @return int <0 if KO, >0 if OK
+ */
+ function setNextDate($date, $increment_nb_gen_done=0)
+ {
+ if (! $this->table_element)
+ {
+ dol_syslog(get_class($this)."::setNextDate was called on objet with property table_element not defined",LOG_ERR);
+ return -1;
+ }
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
+ $sql.= ' SET date_when = "'.$this->db->idate($date).'"';
+ if ($increment_nb_gen_done>0) $sql.= ', nb_gen_done = nb_gen_done + 1';
+ $sql.= ' WHERE rowid = '.$this->id;
+
+ dol_syslog(get_class($this)."::setNextDate", LOG_DEBUG);
+ if ($this->db->query($sql))
+ {
+ $this->date_when = $date;
+ return 1;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
+
+ /**
+ * Update the maximum period
+ *
+ * @param int $nb number of maximum period
+ * @return int <0 if KO, >0 if OK
+ */
+ function setMaxPeriod($nb)
+ {
+ if (! $this->table_element)
+ {
+ dol_syslog(get_class($this)."::setMaxPeriod was called on objet with property table_element not defined",LOG_ERR);
+ return -1;
+ }
+
+ if (empty($nb)) $nb=0;
+
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
+ $sql.= ' SET nb_gen_max = '.$nb;
+ $sql.= ' WHERE rowid = '.$this->id;
+
+ dol_syslog(get_class($this)."::setMaxPeriod", LOG_DEBUG);
+ if ($this->db->query($sql))
+ {
+ $this->nb_gen_max = $nb;
+ return 1;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
+
+ /**
+ * Update the auto validate invoice
+ *
+ * @param int $validate 0 to create in draft, 1 to create and validate invoice
+ * @return int <0 if KO, >0 if OK
+ */
+ function setAutoValidate($validate)
+ {
+ if (! $this->table_element)
+ {
+ dol_syslog(get_class($this)."::setAutoValidate was called on objet with property table_element not defined",LOG_ERR);
+ return -1;
+ }
+
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
+ $sql.= ' SET auto_validate = '.$validate;
+ $sql.= ' WHERE rowid = '.$this->id;
+
+ dol_syslog(get_class($this)."::setAutoValidate", LOG_DEBUG);
+ if ($this->db->query($sql))
+ {
+ $this->auto_validate = $validate;
+ return 1;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
}
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 78ca830a191..18a41145c21 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -278,6 +278,8 @@ class Facture extends CommonInvoice
$result=$_facrec->fetch($this->fac_rec);
$this->fk_project = $_facrec->fk_project;
+ $this->fk_account = $_facrec->fk_account;
+ $this->note_private = $_facrec->note_private;
$this->cond_reglement_id = $_facrec->cond_reglement_id;
$this->mode_reglement_id = $_facrec->mode_reglement_id;
$this->remise_absolue = $_facrec->remise_absolue;
@@ -917,6 +919,60 @@ class Facture extends CommonInvoice
else return -1;
}
+ /**
+ * Create a new invoice in database from facturerec
+ *
+ * @param User $user Object user that ask creation
+ * @param FactureRec $facturerec Object facturerec source
+ * @return int <0 if KO, 0 if not validate, >0 if OK
+ */
+ function createFromRec($user, $facturerec)
+ {
+
+ // Clean parameters
+ $this->type = self::TYPE_STANDARD;
+ $this->brouillon = 1;
+
+ // Charge facture source
+ $facture=new Facture($facturerec->db);
+
+ $facture->socid = $facturerec->socid;
+ $facture->date = dol_mktime(12, 0, 0, date('m'), date('d'), date('Y'));
+ $facture->note_public = $facturerec->note_public;
+ $facture->note_private = $facturerec->note_private;
+ $facture->fk_project = $facturerec->fk_project;
+ $facture->fk_account = $facturerec->fk_account;
+ $facture->cond_reglement_id = $facturerec->cond_reglement_id;
+ $facture->mode_reglement_id = $facturerec->mode_reglement_id;
+
+ $new_date_lim_reglement = $facture->calculate_date_lim_reglement();
+ $facture->date_lim_reglement = $new_date_lim_reglement;
+
+ $facture->remise_absolue = $facturerec->remise_absolue;
+ $facture->remise_percent = $facturerec->remise_percent;
+
+ $facture->lines = $facturerec->lines; // Tableau des lignes de factures
+
+ // Loop on each line of new invoice
+ foreach($facture->lines as $i => $line)
+ {
+ $facture->lines[$i]->fk_prev_id = $facturerec->lines[$i]->rowid;
+ }
+
+ dol_syslog(get_class($this)."::createFromRec socid=".$this->socid." nboflines=".count($facture->lines));
+
+ $facid = $facture->create($user);
+ if ($facid <= 0) return -1;
+
+ if ($facturerec->auto_validate)
+ {
+ $result = $facture->validate($user);
+ if ($result<=0) return 0;
+ }
+
+ return $facid;
+ }
+
/**
* Return clicable link of object (with eventually picto)
*
diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php
index 5f17c5d49bb..42c82a1642d 100644
--- a/htdocs/compta/facture/fiche-rec.php
+++ b/htdocs/compta/facture/fiche-rec.php
@@ -58,7 +58,14 @@ if ($sortfield == "")
$sortfield="f.datef";
$object = new FactureRec($db);
-
+if ($id > 0 && $action != 'create' && $action != 'add')
+{
+ $ret = $object->fetch($id);
+ if (!$ret)
+ {
+ setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
+ }
+}
/*
* Actions
@@ -75,16 +82,50 @@ if ($action == 'add')
$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->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');
+
+ $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
+ $object->date_when = $date_next_execution;
+
if ($object->create($user, $id) > 0)
{
$id = $object->id;
- $action = '';
+ header("Location: " . $_SERVER['PHP_SELF'] . '?facid=' . $id);
+ exit;
}
else
{
@@ -97,12 +138,59 @@ if ($action == 'add')
// Delete
if ($action == 'delete' && $user->rights->facture->supprimer)
{
- $object->fetch($id);
$object->delete();
- $id = 0 ;
+ 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'));
+}
+// Set note
+$permissionnote=$user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php
+include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
+
/*
* View
@@ -133,7 +221,8 @@ if ($action == 'create')
dol_fiche_head();
$rowspan=4;
- if (! empty($conf->projet->enabled) && $object->fk_project > 0) $rowspan++;
+ if (! empty($conf->projet->enabled)) $rowspan++;
+ if ($object->fk_account > 0) $rowspan++;
print '';
@@ -152,7 +241,7 @@ if ($action == 'create')
// Note
print '| ';
- print '';
+ print '';
print ' | ';
// Author
@@ -169,21 +258,61 @@ if ($action == 'create')
print "";
// Project
- if (! empty($conf->projet->enabled) && $object->fk_project > 0)
+ if (! empty($conf->projet->enabled))
{
print "| ".$langs->trans("Project")." | ";
if ($object->fk_project > 0)
{
$project = new Project($db);
$project->fetch($object->fk_project);
- print $project->title;
+ print $project->getNomUrl(1);
}
print " | ";
}
+ // Bank account
+ if ($object->fk_account > 0)
+ {
+ print "| ".$langs->trans('BankAccount')." | ";
+ $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
+ print " | ";
+ }
+
print " ";
- print ' ';
+ print '
';
+
+
+ // Autogeneration
+ $title = $langs->trans("Recurrence");
+ print load_fiche_titre($title, '', 'calendar');
+
+ print '';
+
+ // Frequency
+ print "| ".$form->textwithpicto($langs->trans("Frequency"), $langs->transnoentitiesnoconv('toolTipFrequency'))." | ";
+ print " ".$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 " | ";
+
+ // First date of execution for cron
+ print "| ".$langs->trans('NextDateToExecution')." | ";
+ $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 " | ";
+
+ // Number max of generation
+ print "| ".$langs->trans("MaxPeriodNumber")." | ";
+ print "";
+ print " | ";
+
+ // Auto validate the invoice
+ print "| ".$langs->trans("InvoiceAutoValidate")." | ";
+ print $form->selectyesno('auto_validate', 0, 1);
+ print " | ";
+
+ print " ";
+
+ print '
';
$title = $langs->trans("ProductsAndServices");
if (empty($conf->service->enabled))
@@ -191,7 +320,7 @@ if ($action == 'create')
else if (empty($conf->product->enabled))
$title = $langs->trans("Services");
- print load_fiche_titre($title);
+ print load_fiche_titre($title, '', '');
/*
* Invoice lines
@@ -394,178 +523,346 @@ else
/*
* View mode
*/
- if ($id > 0)
+ if ($object->id > 0)
{
- if ($object->fetch($id) > 0)
+ $object->fetch_thirdparty();
+
+ $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 '';
+
+ $linkback = '' . $langs->trans("BackToList") . '';
+
+ // Ref
+ print '| ' . $langs->trans('Ref') . ' | ';
+ print '';
+ $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, 'facnumber', 'ref', $morehtmlref);
+ print ' | ';
+
+
+ print '| '.$langs->trans("Customer").' | ';
+ print ''.$object->thirdparty->getNomUrl(1,'customer').' | ';
+
+ print "| ".$langs->trans("Author").' | '.$author->getFullName($langs)." | ";
+
+ print '| '.$langs->trans("AmountHT").' | ';
+ print ''.price($object->total_ht,'',$langs,1,-1,-1,$conf->currency).' | ';
+ print ' ';
+
+ print '| '.$langs->trans("AmountVAT").' | '.price($object->total_tva,'',$langs,1,-1,-1,$conf->currency).' | ';
+ print ' ';
+ print '| '.$langs->trans("AmountTTC").' | '.price($object->total_ttc,'',$langs,1,-1,-1,$conf->currency).' | ';
+ print ' ';
+
+ // Payment term
+ print '| ';
+ print '';
+ print ' | ';
+ if ($object->type != Facture::TYPE_CREDIT_NOTE)
{
- $object->fetch_thirdparty();
-
- $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("PredefinedInvoices"),0,'bill'); // Add a div
-
- print '';
-
- print '| '.$langs->trans("Ref").' | ';
- print ''.$object->titre.' | ';
-
- print ' | '.$langs->trans("Customer").' | ';
- print ''.$object->thirdparty->getNomUrl(1,'customer').' | ';
-
- print "| ".$langs->trans("Author").' | '.$author->getFullName($langs)." | ";
-
- print '| '.$langs->trans("AmountHT").' | ';
- print ''.price($object->total_ht,'',$langs,1,-1,-1,$conf->currency).' | ';
- print ' ';
-
- print '| '.$langs->trans("AmountVAT").' | '.price($object->total_tva,'',$langs,1,-1,-1,$conf->currency).' | ';
- print ' ';
- print '| '.$langs->trans("AmountTTC").' | '.price($object->total_ttc,'',$langs,1,-1,-1,$conf->currency).' | ';
- print ' ';
-
- // Payment term
- print '| '.$langs->trans("PaymentConditions").' | ';
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id,'none');
- print " | ";
-
- // Payment mode
- print '| '.$langs->trans("PaymentMode").' | ';
- $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id,'none');
- print " | ";
-
- print '| '.$langs->trans("Comment").' | '.nl2br($object->note_private)." | ";
-
- print " ";
-
- print '';
-
- /*
- * Lines
- */
-
- $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);
-
- print '';
- print '';
- print '| '.$langs->trans("Description").' | ';
- print ''.$langs->trans("Price").' | ';
- print ''.$langs->trans("ReductionShort").' | ';
- print ''.$langs->trans("Qty").' | ';
- if ($conf->global->PRODUCT_USE_UNITS) {
- print ''.$langs->trans("Unit").' | ';
+ 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');
}
- print ' ';
+ } else {
+ print ' ';
+ }
+ print '';
- $num = count($object->lines);
- $i = 0;
- $var=true;
- while ($i < $num)
- {
- $var=!$var;
-
- $product_static=new Product($db);
-
- // Show product and description
- $type=(isset($object->lines[$i]->product_type)?$object->lines[$i]->product_type:$object->lines[$i]->fk_product_type);
- // Try to enhance type detection using date_start and date_end for free lines when type
- // was not saved.
- if (! empty($objp->date_start)) $type=1;
- if (! empty($objp->date_end)) $type=1;
-
- // Show line
- print "";
- if ($object->lines[$i]->fk_product > 0)
- {
- print '';
- print ''; // ancre pour retourner sur la ligne
-
- // Show product and description
- $product_static->type=$object->lines[$i]->fk_product_type;
- $product_static->id=$object->lines[$i]->fk_product;
- $product_static->ref=$object->lines[$i]->product_ref;
- $text=$product_static->getNomUrl(1);
- $text.= ' - '.(! empty($object->lines[$i]->label)?$object->lines[$i]->label:$object->lines[$i]->product_label);
- $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($object->lines[$i]->desc));
- print $form->textwithtooltip($text,$description,3,'','',$i);
-
- // Show range
- print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end);
-
- // Add description in form
- if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
- print (! empty($object->lines[$i]->desc) && $object->lines[$i]->desc!=$fac->lines[$i]->product_label)?' '.dol_htmlentitiesbr($object->lines[$i]->desc):'';
-
- print ' | ';
- }
- else
- {
- print '';
-
- if ($type==1) $text = img_object($langs->trans('Service'),'service');
- else $text = img_object($langs->trans('Product'),'product');
-
- if (! empty($object->lines[$i]->label)) {
-
- $text.= ' '.$object->lines[$i]->label.'';
- print $form->textwithtooltip($text,dol_htmlentitiesbr($object->lines[$i]->desc),3,'','',$i);
-
- } else {
-
- print $text.' '.nl2br($object->lines[$i]->desc);
- }
-
- // Show range
- print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end);
-
- print ' | ';
- }
- print ''.price($object->lines[$i]->price).' | ';
- print ''.$object->lines[$i]->remise_percent.' % | ';
- print ''.$object->lines[$i]->qty.' | ';
- if ($conf->global->PRODUCT_USE_UNITS) {
- print "".$object->lines[$i]->getLabelOfUnit()." | ";
- }
- print " \n";
- $i++;
- }
- print ' ';
-
-
-
- /**
- * Barre d'actions
- */
- print '';
-
- if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->creer)
- {
- echo ' ';
- }
-
- if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->supprimer)
- {
- print ' ';
- }
-
- print ' ';
+ // Payment mode
+ print ' | | ';
+ print '';
+ print ' | ';
+ if ($action == 'editmode')
+ {
+ $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT');
}
else
{
- print $langs->trans("ErrorRecordNotFound");
+ $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->mode_reglement_id, 'none', 'CRDT');
}
+ print ' | ';
+
+
+ print '| ';
+ print $form->editfieldkey($langs->trans("NotePrivate"), 'note_private', $object->note_private, $object, $user->rights->facture->creer);
+ print ' | ';
+ print $form->editfieldval($langs->trans("NotePrivate"), 'note_private', $object->note_private, $object, $user->rights->facture->creer, 'textarea:'.ROWS_4.':60');
+ print ' | ';
+ print ' ';
+
+ // Project
+ if (! empty($conf->projet->enabled)) {
+ $langs->load('projects');
+ print '';
+ print '| ';
+
+ print '';
+
+ print ' | ';
+ 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 ' | ';
+ print ' ';
+ }
+
+ // Bank Account
+ print '| ';
+ print '';
+ print ' | ';
+ 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 " | ";
+ print ' ';
+
+
+ print " ";
+
+ print ' ';
+
+ /*
+ * Recurrence
+ */
+ $title = $langs->trans("Recurrence");
+ print load_fiche_titre($title, '', 'calendar');
+
+ print '';
+
+ // if "frequency" is empty or = 0, the reccurence is disabled
+ print '| ';
+ print '';
+ print ' | ';
+ if ($action == 'editfrequency')
+ {
+ print '';
+ }
+ else
+ {
+ if ($object->frequency > 0)
+ {
+ print $langs->trans('FrequencyPer_'.$object->unit_frequency, $object->frequency);
+ }
+ else
+ {
+ print $langs->trans("NotARecurringInvoiceTemplate");
+ }
+ }
+ print ' | ';
+
+ //if (! empty($object->frequency)) // If no frequency defined, it is not a recurring template invoice
+ //{
+ // Date when
+ print '| ';
+ print $form->editfieldkey($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'dayhour');
+ print ' | ';
+ print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->rights->facture->creer, 'dayhour');
+ print ' | ';
+ print ' ';
+
+
+ // Max period / Rest period
+ print '| ';
+ print $form->editfieldkey($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, $object, $user->rights->facture->creer);
+ print ' | ';
+ print $form->editfieldval($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, $object, $user->rights->facture->creer);
+ print ' | ';
+ print ' ';
+ print '| '.$langs->trans("RestPeriodNumber").' | ';
+ print '';
+ print ($object->nb_gen_max-$object->nb_gen_done);
+ print ' | ';
+
+ // Auto validate
+ print ' | ';
+ print $form->editfieldkey($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer);
+ print ' | ';
+ $select = 'select;0:'.$langs->trans('BillStatusDraft').',1:'.$langs->trans('BillStatusValidated');
+ print $form->editfieldval($langs->trans("StatusOfGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->rights->facture->creer, $select);
+ print ' | ';
+ print ' ';
+ //}
+
+ print ' ';
+
+ print ' ';
+
+ /*
+ * Lines
+ */
+
+ print '';
+ print '';
+ print '| '.$langs->trans("Description").' | ';
+ print ''.$langs->trans("VAT").' | ';
+ print ''.$langs->trans("PriceUHT").' | ';
+ print ''.$langs->trans("Qty").' | ';
+ print ''.$langs->trans("ReductionShort").' | ';
+ if ($conf->global->PRODUCT_USE_UNITS) {
+ print ''.$langs->trans("Unit").' | ';
+ }
+ print ' ';
+
+ $num = count($object->lines);
+ $i = 0;
+ $var=true;
+ while ($i < $num)
+ {
+ $var=!$var;
+
+ $product_static=new Product($db);
+
+ // Show product and description
+ $type=(isset($object->lines[$i]->product_type)?$object->lines[$i]->product_type:$object->lines[$i]->fk_product_type);
+ // Try to enhance type detection using date_start and date_end for free lines when type
+ // was not saved.
+ if (! empty($objp->date_start)) $type=1;
+ if (! empty($objp->date_end)) $type=1;
+
+ // Show line
+ print "";
+ if ($object->lines[$i]->fk_product > 0)
+ {
+ print '';
+ print ''; // ancre pour retourner sur la ligne
+
+ // Show product and description
+ $product_static->type=$object->lines[$i]->fk_product_type;
+ $product_static->id=$object->lines[$i]->fk_product;
+ $product_static->ref=$object->lines[$i]->product_ref;
+ $text=$product_static->getNomUrl(1);
+ $text.= ' - '.(! empty($object->lines[$i]->label)?$object->lines[$i]->label:$object->lines[$i]->product_label);
+ $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($object->lines[$i]->desc));
+ print $form->textwithtooltip($text,$description,3,'','',$i);
+
+ // Show range
+ print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end);
+
+ // Add description in form
+ if (! empty($conf->global->PRODUIT_DESC_IN_FORM))
+ print (! empty($object->lines[$i]->desc) && $object->lines[$i]->desc!=$fac->lines[$i]->product_label)?' '.dol_htmlentitiesbr($object->lines[$i]->desc):'';
+
+ print ' | ';
+ }
+ else
+ {
+ print '';
+
+ if ($type==1) $text = img_object($langs->trans('Service'),'service');
+ else $text = img_object($langs->trans('Product'),'product');
+
+ if (! empty($object->lines[$i]->label)) {
+
+ $text.= ' '.$object->lines[$i]->label.'';
+ print $form->textwithtooltip($text,dol_htmlentitiesbr($object->lines[$i]->desc),3,'','',$i);
+
+ } else {
+
+ print $text.' '.nl2br($object->lines[$i]->desc);
+ }
+
+ // Show range
+ print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end);
+
+ print ' | ';
+ }
+ print ''.vatrate($object->lines[$i]->tva_tx, 1).' | ';
+ print ''.price($object->lines[$i]->price).' | ';
+ print ''.$object->lines[$i]->qty.' | ';
+ print ''.$object->lines[$i]->remise_percent.' % | ';
+ if ($conf->global->PRODUCT_USE_UNITS) {
+ print "".$object->lines[$i]->getLabelOfUnit()." | ";
+ }
+ print " \n";
+ $i++;
+ }
+ print ' ';
+
+ dol_fiche_end();
+
+
+ /**
+ * Barre d'actions
+ */
+ print '';
+
+ if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->creer)
+ {
+ echo ' ';
+ }
+
+ if ($object->statut == Facture::STATUS_DRAFT && $user->rights->facture->supprimer)
+ {
+ print ' ';
+ }
+
+ print ' ';
+
}
else
{
diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php
index af0376fef0e..38d1ce96f59 100644
--- a/htdocs/compta/facture/list.php
+++ b/htdocs/compta/facture/list.php
@@ -1,7 +1,7 @@
* Copyright (C) 2004 Eric Seigne
- * Copyright (C) 2004-2012 Laurent Destailleur
+ * Copyright (C) 2004-2016 Laurent Destailleur
* Copyright (C) 2005 Marc Barilley / Ocebo
* Copyright (C) 2005-2015 Regis Houssin
* Copyright (C) 2006 Andre Cianfarani
@@ -695,6 +695,7 @@ if ($resql)
}
$param='&socid='.$socid;
+ if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
if ($month) $param.='&month='.$month;
if ($year) $param.='&year=' .$year;
if ($search_ref) $param.='&search_ref=' .$search_ref;
@@ -712,8 +713,7 @@ if ($resql)
$i = 0;
print '';
-
- if ($num > $limit) print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');
-
+
$db->free($result);
}
else
diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php
index f9e7351ed87..df6e0007023 100644
--- a/htdocs/contrat/list.php
+++ b/htdocs/contrat/list.php
@@ -36,13 +36,6 @@ $langs->load("products");
$langs->load("companies");
$langs->load("compta");
-$sortfield=GETPOST('sortfield','alpha');
-$sortorder=GETPOST('sortorder','alpha');
-$page=GETPOST('page','int');
-if ($page == -1) { $page = 0 ; }
-$limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
-$offset = $limit * $page ;
-
$search_name=GETPOST('search_name');
$search_contract=GETPOST('search_contract');
$search_ref_supplier=GETPOST('search_ref_supplier','alpha');
@@ -55,8 +48,16 @@ $search_product_category=GETPOST('search_product_category','int');
$optioncss = GETPOST('optioncss','alpha');
-if (! $sortfield) $sortfield="c.rowid";
-if (! $sortorder) $sortorder="DESC";
+$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;
+$pageprev = $page - 1;
+$pagenext = $page + 1;
+if (! $sortfield) $sortfield='c.ref';
+if (! $sortorder) $sortorder='DESC';
// Security check
$id=GETPOST('id','int');
@@ -152,7 +153,15 @@ if ($result)
$totalnboflines = $db->num_rows($result);
}
$sql.= $db->order($sortfield,$sortorder);
-$sql.= $db->plimit($conf->liste_limit + 1, $offset);
+
+$nbtotalofrecords = 0;
+if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
+{
+ $result = $db->query($sql);
+ $nbtotalofrecords = $db->num_rows($result);
+}
+
+$sql.= $db->plimit($limit + 1, $offset);
$resql=$db->query($sql);
if ($resql)
@@ -160,8 +169,14 @@ if ($resql)
$num = $db->num_rows($resql);
$i = 0;
- print_barre_liste($langs->trans("ListOfContracts"), $page, $_SERVER["PHP_SELF"], '&search_contract='.$search_contract.'&search_name='.$search_name, $sortfield, $sortorder,'',$num,$totalnboflines,'title_commercial.png');
-
+ $param='';
+ if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
+ $param.='&search_contract='.$search_contract;
+ $param.='&search_name='.$search_name;
+ $param.='&search_ref_supplier='.$search_ref_supplier;
+ $param.='&search_sale=' .$search_sale;
+ if ($optioncss != '') $param.='&optioncss='.$optioncss;
+
print ' |