diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index d26e8e44078..1190e98a799 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -720,7 +720,8 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if (empty($leftmenu) || $leftmenu=="orders_suppliers") $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=5", $langs->trans("StatusOrderReceivedAll"), 2, $user->rights->fournisseur->commande->lire); if (empty($leftmenu) || $leftmenu=="orders_suppliers") $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=6,7", $langs->trans("StatusOrderCanceled"), 2, $user->rights->fournisseur->commande->lire); if (empty($leftmenu) || $leftmenu=="orders_suppliers") $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&statut=9", $langs->trans("StatusOrderRefused"), 2, $user->rights->fournisseur->commande->lire); - + if (empty($leftmenu) || $leftmenu=="orders_suppliers") $newmenu->add("/fourn/commande/list.php?leftmenu=orders_suppliers&billed=1", $langs->trans("StatusOrderBilled"), 2, $user->rights->fournisseur->commande->lire); + $newmenu->add("/commande/stats/index.php?leftmenu=orders_suppliers&mode=supplier", $langs->trans("Statistics"), 1, $user->rights->fournisseur->commande->lire); } diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index cab8c96b62a..6613cd8f05c 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -366,8 +366,10 @@ if ($object->id > 0) $sql2.= ' AND s.rowid = '.$object->id; // Show orders with status validated, shipping started and delivered (well any order we can bill) $sql2.= " AND c.fk_statut IN (5)"; + $sql2.= " AND c.billed = 0"; // Find order that are not already invoiced - $sql2 .= " AND c.rowid NOT IN (SELECT fk_source FROM " . MAIN_DB_PREFIX . "element_element WHERE targettype='invoice_supplier')"; + // just need to check received status because we have the billed status now + //$sql2 .= " AND c.rowid NOT IN (SELECT fk_source FROM " . MAIN_DB_PREFIX . "element_element WHERE targettype='invoice_supplier')"; $resql2=$db->query($sql2); if ($resql2) { $orders2invoice = $db->num_rows($resql2); diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 3f9d7b1246a..5d509f8fd3a 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -140,6 +140,7 @@ class CommandeFournisseur extends CommonOrder $this->statuts[5] = 'StatusOrderReceivedAll'; $this->statuts[6] = 'StatusOrderCanceled'; // Approved->Canceled $this->statuts[7] = 'StatusOrderCanceled'; // Process running->canceled + $this->statuts[8] = 'StatusOrderBilled'; // Everything is finish, order received totally and bill received $this->statuts[9] = 'StatusOrderRefused'; } @@ -164,7 +165,7 @@ class CommandeFournisseur extends CommonOrder $sql.= " c.fk_user_author, c.fk_user_valid, c.fk_user_approve, c.fk_user_approve2,"; $sql.= " c.date_commande as date_commande, c.date_livraison as date_livraison, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_projet as fk_project, c.remise_percent, c.source, c.fk_input_method,"; $sql.= " c.fk_account,"; - $sql.= " c.note_private, c.note_public, c.model_pdf, c.extraparams,"; + $sql.= " c.note_private, c.note_public, c.model_pdf, c.extraparams, c.billed,"; $sql.= " cm.libelle as methode_commande,"; $sql.= " cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle,"; $sql.= " p.code as mode_reglement_code, p.libelle as mode_reglement_libelle"; @@ -197,6 +198,7 @@ class CommandeFournisseur extends CommonOrder $this->socid = $obj->fk_soc; $this->fourn_id = $obj->fk_soc; $this->statut = $obj->fk_statut; + $this->billed = $obj->billed; $this->user_author_id = $obj->fk_user_author; $this->user_valid_id = $obj->fk_user_valid; $this->user_approve_id = $obj->fk_user_approve; @@ -217,7 +219,6 @@ class CommandeFournisseur extends CommonOrder $this->methode_commande = $obj->methode_commande; $this->source = $obj->source; - //$this->facturee = $obj->facture; $this->fk_project = $obj->fk_project; $this->cond_reglement_id = $obj->fk_cond_reglement; $this->cond_reglement_code = $obj->cond_reglement_code; @@ -250,6 +251,7 @@ class CommandeFournisseur extends CommonOrder if ($this->statut == 0) $this->brouillon = 1; + $this->fetchObjectLinked(); $sql = "SELECT l.rowid, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description,"; $sql.= " l.qty,"; @@ -510,6 +512,8 @@ class CommandeFournisseur extends CommonOrder global $langs; $langs->load('orders'); + if($statut==5 && $this->billed == 1) $statut = 8; + // List of language codes for status $statutshort[0] = 'StatusOrderDraftShort'; $statutshort[1] = 'StatusOrderValidatedShort'; @@ -519,6 +523,7 @@ class CommandeFournisseur extends CommonOrder $statutshort[5] = 'StatusOrderReceivedAllShort'; $statutshort[6] = 'StatusOrderCanceledShort'; $statutshort[7] = 'StatusOrderCanceledShort'; + $statutshort[8] = 'StatusOrderBilledShort'; $statutshort[9] = 'StatusOrderRefusedShort'; if ($mode == 0) @@ -542,6 +547,7 @@ class CommandeFournisseur extends CommonOrder if ($statut==4) return img_picto($langs->trans($this->statuts[$statut]),'statut3'); if ($statut==5) return img_picto($langs->trans($this->statuts[$statut]),'statut6'); if ($statut==6 || $statut==7) return img_picto($langs->trans($this->statuts[$statut]),'statut5'); + if ($statut==8) return img_picto($langs->trans($this->statuts[$statut]),'statut6'); if ($statut==9) return img_picto($langs->trans($this->statuts[$statut]),'statut5'); } if ($mode == 4) @@ -553,6 +559,7 @@ class CommandeFournisseur extends CommonOrder if ($statut==4) return img_picto($langs->trans($this->statuts[$statut]),'statut3').' '.$langs->trans($this->statuts[$statut]); if ($statut==5) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]); if ($statut==6 || $statut==7) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]); + if ($statut==8) return img_picto($langs->trans($this->statuts[$statut]),'statut6').' '.$langs->trans($this->statuts[$statut]); if ($statut==9) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]); } if ($mode == 5) @@ -564,6 +571,7 @@ class CommandeFournisseur extends CommonOrder if ($statut==4) return ''.$langs->trans($statutshort[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut3'); if ($statut==5) return ''.$langs->trans($statutshort[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut6'); if ($statut==6 || $statut==7) return ''.$langs->trans($statutshort[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5'); + if ($statut==8) return ''.$langs->trans($statutshort[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut6'); if ($statut==9) return ''.$langs->trans($statutshort[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5'); } } @@ -660,6 +668,26 @@ class CommandeFournisseur extends CommonOrder return -2; } } + /** + * Class invoiced the supplier order + * + * @return int <0 si ko, >0 si ok + */ + function classifyBilled() + { + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur SET billed = 1'; + $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 '; + if ($this->db->query($sql) ) + { + $this->billed=1; + return 1; + } + else + { + dol_print_error($this->db); + return -1; + } + } /** * Approve a supplier order diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 83b94bd74d9..9a1a6ec67d4 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -234,6 +234,17 @@ if (empty($reshook)) } } + /* + * Classify supplier order as billed + */ + if ($action == 'classifybilled' && $user->rights->fournisseur->commande->creer) + { + $ret=$object->classifyBilled(); + if ($ret < 0) { + setEventMessage($object->error, 'errors'); + } + } + /* * Add a line into product */ @@ -2725,18 +2736,19 @@ elseif (! empty($object->id)) // Create bill if (! empty($conf->facture->enabled)) { - if (! empty($conf->fournisseur->enabled) && ($object->statut >= 2 && $object->statut != 9)) // 2 means accepted + if (! empty($conf->fournisseur->enabled) && ($object->statut >= 2 && $object->billed != 1)) // 2 means accepted { if ($user->rights->fournisseur->facture->creer) { print ''.$langs->trans("CreateBill").''; } - - //if ($user->rights->fournisseur->commande->creer && $object->statut > 2) - //{ - // print 'id.'&action=classifybilled">'.$langs->trans("ClassifyBilled").''; - //} + + if ($user->rights->fournisseur->commande->creer && $object->statut >= 2 && !empty($object->linkedObjectsIds['invoice_supplier'])) + { + print 'id.'&action=classifybilled">'.$langs->trans("ClassifyBilled").''; + } } + } // Create a remote order using WebService only if module is activated diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php index ccffe5afa90..dea0f72b628 100644 --- a/htdocs/fourn/commande/list.php +++ b/htdocs/fourn/commande/list.php @@ -167,6 +167,12 @@ if (GETPOST('statut', 'alpha') !== '') { $sql .= " AND cf.fk_statut IN (".GETPOST('statut', 'alpha').")"; } + +if (GETPOST('billed', 'int') !== '') +{ + $sql .= " AND cf.billed IN (".GETPOST('billed', 'int').")"; +} + if ($search_refsupp) { $sql.= " AND (cf.ref_supplier LIKE '%".$db->escape($search_refsupp)."%')"; diff --git a/htdocs/fourn/commande/orderstoinvoice.php b/htdocs/fourn/commande/orderstoinvoice.php index 2c12a9ccdcc..d0502ed927a 100644 --- a/htdocs/fourn/commande/orderstoinvoice.php +++ b/htdocs/fourn/commande/orderstoinvoice.php @@ -236,9 +236,32 @@ if (($action == 'create' || $action == 'add') && empty($mesgs)) { // End of object creation, we show it if ($id > 0 && ! $error) { - $db->commit(); - header('Location: ' . DOL_URL_ROOT . '/fourn/facture/card.php?facid=' . $id); - exit(); + + foreach($orders_id as $fk_supplier_order) { + $supplier_order = new CommandeFournisseur($db); + if($supplier_order->fetch($fk_supplier_order)>0 && $supplier_order->statut == 5) { + + if($supplier_order->classifyBilled()<0) { + + $db->rollback(); + $action = 'create'; + $_GET["origin"] = $_POST["origin"]; + $_GET["originid"] = $_POST["originid"]; + $mesgs[] = '