* Copyright (C) 2003 Eric Seigne * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2010-2015 Juanjo Menent * Copyright (C) 2014 Jean Heimburger * Copyright (C) 2015 Marcos García * Copyright (C) 2015 Raphaël Doursenaud * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/fourn/card.php * \ingroup fournisseur, facture * \brief Page for supplier third party card (view, edit) */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; $langs->load('companies'); $langs->load('suppliers'); $langs->load('products'); $langs->load('bills'); $langs->load('orders'); $langs->load('commercial'); $action = GETPOST('action'); $cancelbutton = GETPOST('cancel'); // Security check $id = (GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int')); if ($user->societe_id) $id=$user->societe_id; $result = restrictedArea($user, 'societe&fournisseur', $id, '&societe'); $object = new Fournisseur($db); $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('suppliercard','globalcard')); /* * Action */ $parameters=array('socid'=>$socid); $reshook=$hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if (empty($reshook)) { if ($cancelbutton) { $action = ""; } if ($action == 'setsupplieraccountancycode') { $result=$object->fetch($id); $object->code_compta_fournisseur=$_POST["supplieraccountancycode"]; $result=$object->update($object->id,$user,1,0,1); if ($result < 0) { $mesg=join(',',$object->errors); } } // conditions de reglement if ($action == 'setconditions' && $user->rights->societe->creer) { $object->fetch($id); $result=$object->setPaymentTerms(GETPOST('cond_reglement_supplier_id','int')); if ($result < 0) dol_print_error($db,$object->error); } // mode de reglement if ($action == 'setmode' && $user->rights->societe->creer) { $object->fetch($id); $result=$object->setPaymentMethods(GETPOST('mode_reglement_supplier_id','int')); if ($result < 0) dol_print_error($db,$object->error); } } /* * View */ $contactstatic = new Contact($db); $form = new Form($db); if ($id > 0 && empty($object->id)) { // Load data of third party $res=$object->fetch($id); if ($object->id <= 0) dol_print_error($db,$object->error); } if ($object->id > 0) { $title=$langs->trans("ThirdParty")." - ".$langs->trans('SupplierCard'); if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$langs->trans('SupplierCard'); $help_url=''; llxHeader('',$title, $help_url); /* * Show tabs */ $head = societe_prepare_head($object); dol_fiche_head($head, 'supplier', $langs->trans("ThirdParty"),0,'company'); print '
'; print ''; print ''; // Alias names (commercial, trademark or alias names) print '"; if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field { print ''; } if ($object->fournisseur) { print ''; print ''; print ''; $langs->load('compta'); print ''; print ''; print ''; } // Address print ''; // Zip / Town print ''; print ''; // Country print ''; // EMail print ''; // Web print ''; // Phone print ''; // Fax print ''; // Assujetti a TVA ou pas print ''; print ''; print ''; // Local Taxes if ($mysoc->useLocalTax(1)) { print ''; } if ($mysoc->useLocalTax(2)) { print ''; } // TVA Intra print ''; // Conditions de reglement par defaut $langs->load('bills'); $form = new Form($db); print '"; print ''; // Mode de reglement par defaut print '"; print ''; // Categories print ''; print '"; // Other attributes $parameters=array('socid'=>$object->id, 'colspan' => ' colspan="3"', 'colspanvalue' => '3'); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields); } // Module Adherent if (! empty($conf->adherent->enabled)) { $langs->load("members"); $langs->load("users"); print ''; print ''; print "\n"; } print '
'.$langs->trans("ThirdPartyName").''; print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','',''); print '
'.$langs->trans('AliasNameShort').''; print $object->name_alias; print "
'.$langs->trans('Prefix').''.$object->prefix_comm.'
'.$langs->trans("SupplierCode"). ''; print $object->code_fournisseur; if ($object->check_codefournisseur() <> 0) print ' ('.$langs->trans("WrongSupplierCode").')'; print '
'; print $form->editfieldkey("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer); print ''; print $form->editfieldval("SupplierAccountancyCode",'supplieraccountancycode',$object->code_compta_fournisseur,$object,$user->rights->societe->creer); print '
'.$langs->trans("Address").''; dol_print_address($object->address,'gmap','thirdparty',$object->id); print '
'.$langs->trans("Zip").' / '.$langs->trans("Town").''.$object->zip.(($object->zip && $object->town)?' / ':'').$object->town.'
'.$langs->trans("Country").''; //$img=picto_from_langcode($object->country_code); $img=''; if ($object->isInEEC()) print $form->textwithpicto(($img?$img.' ':'').$object->country,$langs->trans("CountryIsInEEC"),1,0); else print ($img?$img.' ':'').$object->country; print '
'.$langs->trans('EMail').''.dol_print_email($object->email,0,$object->id,'AC_EMAIL').'
'.$langs->trans("Web").''.dol_print_url($object->url).'
'.$langs->trans("Phone").''.dol_print_phone($object->phone,$object->country_code,0,$object->id,'AC_TEL').''.$langs->trans("Fax").''.dol_print_phone($object->fax,$object->country_code,0,$object->id,'AC_FAX').'
'.$langs->trans('VATIsUsed').''; print yn($object->tva_assuj); print '
'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).''; print yn($object->localtax1_assuj); print '
'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).''; print yn($object->localtax2_assuj); print '
'.$langs->trans('VATIntra').''; print $object->tva_intra; print '
'; print ''; print '
'; print $langs->trans('PaymentConditions'); print ''; if (($action != 'editconditions') && $user->rights->societe->creer) print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; print '
'; if ($action == 'editconditions') { $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->cond_reglement_supplier_id,'cond_reglement_supplier_id',-1,1); } else { $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->cond_reglement_supplier_id,'none'); } print "
'; print ''; print '
'; print $langs->trans('PaymentMode'); print ''; if (($action != 'editmode') && $user->rights->societe->creer) print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; print '
'; if ($action == 'editmode') { $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_supplier_id,'mode_reglement_supplier_id'); } else { $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->mode_reglement_supplier_id,'none'); } print "
' . $langs->trans("Categories") . ''; print $form->showCategories($object->id, 'supplier', 1); print "
'.$langs->trans("LinkedToDolibarrMember").''; $adh=new Adherent($db); $result=$adh->fetch('','',$object->id); if ($result > 0) { $adh->ref=$adh->getFullName($langs); print $adh->getNomUrl(1); } else { print $langs->trans("ThirdpartyNotLinkedToMember"); } print '
'; print '
'; $var=true; $MAXLIST=5; // Lien recap print ''; print ''; print ''; print ''; print '
'; print '
'.$langs->trans("Summary").''.$langs->trans("ShowSupplierPreview").'
'; print '
'; /* * List of products */ if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { $langs->load("products"); print ''; print ''; print ''; //Query from product/liste.php $sql = 'SELECT p.rowid, p.ref, p.label, pfp.tms,'; $sql.= ' p.fk_product_type'; $sql.= ' FROM '.MAIN_DB_PREFIX.'product_fournisseur_price as pfp'; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = pfp.fk_product"; $sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')'; $sql.= ' AND pfp.fk_soc = '.$object->id; $sql .= $db->order('pfp.tms', 'desc'); $sql.= $db->plimit($MAXLIST); $query = $db->query($sql); $return = array(); if ($db->num_rows($query)) { $productstatic = new Product($db); while ($objp = $db->fetch_object($query)) { $var=!$var; $productstatic->id = $objp->rowid; $productstatic->ref = $objp->ref; $productstatic->label = $objp->label; $productstatic->type = $objp->fk_product_type; print ""; print ''; print ''; print ''; print ''; } } print '
'.$langs->trans("ProductsAndServices").''; print ''.$langs->trans("All").' '.$object->nbOfProductRefs().''; print '
'; print $productstatic->getNomUrl(1); print ''; print dol_trunc(dol_htmlentities($objp->label), 30); print ''.dol_print_date($objp->tms).'
'; } /* * Last supplier orders */ $orderstatic = new CommandeFournisseur($db); if ($user->rights->fournisseur->commande->lire) { // TODO move to DAO class // Check if there are supplier orders billable $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_supplier,'; $sql2.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut'; $sql2.= ' FROM '.MAIN_DB_PREFIX.'societe as s'; $sql2.= ', '.MAIN_DB_PREFIX.'commande_fournisseur as c'; $sql2.= ' WHERE c.fk_soc = s.rowid'; $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)"; // 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')"; $resql2=$db->query($sql2); if ($resql2) { $orders2invoice = $db->num_rows($resql2); $db->free($resql2); } else { setEventMessage($db->lasterror(),'errors'); } // TODO move to DAO class $sql = "SELECT p.rowid,p.ref, p.date_commande as dc, p.fk_statut, p.total_ht, p.tva as total_tva, p.total_ttc"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p "; $sql.= " WHERE p.fk_soc =".$object->id; $sql.= " AND p.entity =".$conf->entity; $sql.= " ORDER BY p.date_commande DESC"; $sql.= " ".$db->plimit($MAXLIST); $resql=$db->query($sql); if ($resql) { $i = 0 ; $num = $db->num_rows($resql); if ($num > 0) { print ''; print ''; print ''; } $var = True; while ($i < $num && $i <= $MAXLIST) { $obj = $db->fetch_object($resql); $var=!$var; print ""; print ''; print ''; print ''; print ''; $i++; } $db->free($resql); if ($num >0) print "
'; print ''; print ''; print ''; print '
'.$langs->trans("LastSupplierOrders",($num<$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllOrders").' '.$num.''.img_picto($langs->trans("Statistics"),'stats').'
'; print '
'; $orderstatic->id = $obj->rowid; $orderstatic->ref = $obj->ref; $orderstatic->total_ht = $obj->total_ht; $orderstatic->total_tva = $obj->total_tva; $orderstatic->total_ttc = $obj->total_ttc; print $orderstatic->getNomUrl(1); print ''; if ($obj->dc) { print dol_print_date($db->jdate($obj->dc),'day'); } else { print "-"; } print ''.$orderstatic->LibStatut($obj->fk_statut,5).'
"; } else { dol_print_error($db); } } /* * Last supplier invoices */ $MAXLIST=5; $langs->load('bills'); $facturestatic = new FactureFournisseur($db); if ($user->rights->fournisseur->facture->lire) { // TODO move to DAO class $sql = 'SELECT f.rowid,f.libelle,f.ref,f.ref_supplier,f.fk_statut,f.datef as df, f.total_ht, f.total_tva, f.total_ttc as amount,f.paye,'; $sql.= ' SUM(pf.amount) as am'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn as f'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON f.rowid=pf.fk_facturefourn'; $sql.= ' WHERE f.fk_soc = '.$object->id; $sql.= " AND f.entity =".$conf->entity; $sql.= ' GROUP BY f.rowid,f.libelle,f.ref,f.ref_supplier,f.fk_statut,f.datef,f.total_ht,f.total_tva,f.total_ttc,f.paye'; $sql.= ' ORDER BY f.datef DESC'; $resql=$db->query($sql); if ($resql) { $i = 0 ; $num = $db->num_rows($resql); if ($num > 0) { print ''; print ''; print ''; } $var=True; while ($i < min($num,$MAXLIST)) { $obj = $db->fetch_object($resql); $var=!$var; print ''; print ''; print ''; print ''; print ''; print ''; $i++; } $db->free($resql); if ($num > 0) print '
'; print ''; print ''; print '
'.$langs->trans('LastSuppliersBills',($num<=$MAXLIST?"":$MAXLIST)).''.$langs->trans('AllBills').' '.$num.''.img_picto($langs->trans("Statistics"),'stats').'
'; print '
'; print ''; $facturestatic->id=$obj->rowid; $facturestatic->ref=($obj->ref?$obj->ref:$obj->rowid).($obj->ref_supplier?' - '.$obj->ref_supplier:''); $facturestatic->ref_supplier = $obj->ref_supplier; $facturestatic->total_ht = $obj->total_ht; $facturestatic->total_tva = $obj->total_tva; $facturestatic->total_ttc = $obj->total_ttc; //$facturestatic->ref_supplier=$obj->ref_supplier; print $facturestatic->getNomUrl(1); //print img_object($langs->trans('ShowBill'),'bill').' '.($obj->ref?$obj->ref:$obj->rowid).' - '.$obj->ref_supplier.''; print ' '.dol_trunc($obj->libelle,14); print ''.dol_print_date($db->jdate($obj->df),'day').''.price($obj->amount).''; print $facturestatic->LibStatut($obj->paye,$obj->fk_statut,5,$obj->am); print '
'; } else { dol_print_error($db); } } print '
'; print '
'; dol_fiche_end(); /* * Barre d'actions */ $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been // modified by hook if (empty($reshook)) { print '
'; if ($user->rights->fournisseur->commande->creer) { $langs->load("orders"); print ''.$langs->trans("AddOrder").''; } if ($user->rights->fournisseur->facture->creer) { $langs->load("bills"); print ''.$langs->trans("AddBill").''; } if ($conf->askpricesupplier->enabled && $user->rights->askpricesupplier->creer) { $langs->load("askpricesupplier"); print ''.$langs->trans("AddAskPriceSupplier").''; } if ($user->rights->fournisseur->facture->creer) { if (! empty($orders2invoice) && $orders2invoice > 0) print ''; else print ''; } // Add action if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB)) { if ($user->rights->agenda->myactions->create) { print ''.$langs->trans("AddAction").''; } else { print ''.$langs->trans("AddAction").''; } } print '
'; print '
'; if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB)) { print '
'; // List of contacts show_contacts($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id); } // Addresses list if (! empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) && ! empty($conf->global->MAIN_REPEATADDRESSONEACHTAB)) { $result=show_addresses($conf,$langs,$db,$object,$_SERVER["PHP_SELF"].'?socid='.$object->id); } if (! empty($conf->global->MAIN_REPEATTASKONEACHTAB)) { print load_fiche_titre($langs->trans("ActionsOnCompany"),'',''); // List of todo actions show_actions_todo($conf,$langs,$db,$object); // List of done actions show_actions_done($conf,$langs,$db,$object); } } } else { dol_print_error($db); } llxFooter(); $db->close();