* Copyright (C) 2003 Eric Seigne * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2010-2013 Juanjo Menent * * 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/fiche.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'; if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; $langs->load('suppliers'); $langs->load('products'); $langs->load('bills'); $langs->load('orders'); $langs->load('companies'); $langs->load('commercial'); $action = GETPOST('action'); // 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); /* * 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); } $action=""; } // 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 ($object->fetch($id)) { llxHeader('',$langs->trans('SupplierCard')); /* * Affichage onglets */ $head = societe_prepare_head($object); dol_fiche_head($head, 'supplier', $langs->trans("ThirdParty"),0,'company'); print '
'; print ''; 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 //TODO: Place into a function to control showing by country or study better option if($mysoc->country_code=='ES') { if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1") { print ''; print ''; } elseif($mysoc->localtax1_assuj=="1") { print ''; } elseif($mysoc->localtax2_assuj=="1") { print ''; } if ($mysoc->localtax2_assuj!="1") { 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 ''; // Module Adherent if (! empty($conf->adherent->enabled)) { $langs->load("members"); $langs->load("users"); print ''; print ''; print "\n"; } print '
'.$langs->trans("ThirdPartyName").''; $object->next_prev_filter="te.fournisseur = 1"; print $form->showrefnav($object,'socid','',($user->societe_id?0:1),'rowid','nom','',''); 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); 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->trans('LocalTax1IsUsedES').''; print yn($object->localtax1_assuj); print '
'.$langs->trans('LocalTax2IsUsedES').''; print yn($object->localtax2_assuj); print '
'.$langs->trans("LocalTax1IsUsedES").''; print yn($object->localtax1_assuj); print '
'.$langs->trans("LocalTax2IsUsedES").''; print yn($object->localtax2_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("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").'
'; /* * List of products */ if (! empty($conf->product->enabled) || ! empty($conf->service->enabled)) { $langs->load("products"); print ''; print ''; print '
'.$langs->trans("ProductsAndServices").''; print ''.$langs->trans("All").' ('.$object->nbOfProductRefs().')'; print '
'; } print '
'; /* * Last orders */ $orderstatic = new CommandeFournisseur($db); if ($user->rights->fournisseur->commande->lire) { // TODO move to DAO class $sql = "SELECT p.rowid,p.ref, p.date_commande as dc, p.fk_statut"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p "; $sql.= " WHERE p.fk_soc =".$object->id; $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 ''; } 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("LastOrders",($num<$MAXLIST?"":$MAXLIST)).''.$langs->trans("AllOrders").' ('.$num.')'.img_picto($langs->trans("Statistics"),'stats').'
'; print '
'.img_object($langs->trans("ShowOrder"),"order")." ".$obj->ref.''; 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 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_supplier,f.fk_statut,f.datef as df,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.= ' GROUP BY f.rowid,f.libelle,f.ref_supplier,f.fk_statut,f.datef,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 ''; } 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 ''; print img_object($langs->trans('ShowBill'),'bill').' '.$obj->ref_supplier.' '.dol_trunc($obj->libelle,14).''.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 */ 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").''; } // 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();