diff --git a/htdocs/contrat/fiche.php b/htdocs/contrat/fiche.php
index 94f06ed0b5a..77c028e944f 100644
--- a/htdocs/contrat/fiche.php
+++ b/htdocs/contrat/fiche.php
@@ -43,13 +43,15 @@ $langs->load("bills");
$langs->load("products");
// Security check
-$socid=GETPOST("socid");
-$contratid = isset($_GET["id"])?$_GET["id"]:'';
+$socid = GETPOST("socid");
+$contratid = GETPOST("id");
if ($user->societe_id) $socid=$user->societe_id;
$result=restrictedArea($user,'contrat',$contratid,'contrat');
$usehm=$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE;
+$object = new Contrat($db);
+
/*
* Actions
@@ -57,33 +59,31 @@ $usehm=$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE;
if ($_REQUEST["action"] == 'confirm_active' && $_REQUEST["confirm"] == 'yes' && $user->rights->contrat->activer)
{
- $contrat = new Contrat($db);
- $contrat->fetch($_GET["id"]);
- $result = $contrat->active_line($user, $_GET["ligne"], $_GET["date"], $_GET["dateend"], $_GET["comment"]);
+ $object->fetch($_GET["id"]);
+ $result = $object->active_line($user, $_GET["ligne"], $_GET["date"], $_GET["dateend"], $_GET["comment"]);
if ($result > 0)
{
- Header("Location: fiche.php?id=".$contrat->id);
+ Header("Location: fiche.php?id=".$object->id);
exit;
}
else {
- $mesg=$contrat->error;
+ $mesg=$object->error;
}
}
if ($_REQUEST["action"] == 'confirm_closeline' && $_REQUEST["confirm"] == 'yes' && $user->rights->contrat->activer)
{
- $contrat = new Contrat($db);
- $contrat->fetch($_GET["id"]);
- $result = $contrat->close_line($user, $_GET["ligne"], $_GET["dateend"], urldecode($_GET["comment"]));
+ $object->fetch($_GET["id"]);
+ $result = $object->close_line($user, $_GET["ligne"], $_GET["dateend"], urldecode($_GET["comment"]));
if ($result > 0)
{
- Header("Location: fiche.php?id=".$contrat->id);
+ Header("Location: fiche.php?id=".$object->id);
exit;
}
else {
- $mesg=$contrat->error;
+ $mesg=$object->error;
}
}
@@ -146,27 +146,25 @@ if ($_POST["remonth"] && $_POST["reday"] && $_POST["reyear"])
if ($_POST["action"] == 'add')
{
- $contrat = new Contrat($db);
+ $object->socid = $_POST["socid"];
+ $object->date_contrat = $datecontrat;
- $contrat->socid = $_POST["socid"];
- $contrat->date_contrat = $datecontrat;
+ $object->commercial_suivi_id = $_POST["commercial_suivi_id"];
+ $object->commercial_signature_id = $_POST["commercial_signature_id"];
- $contrat->commercial_suivi_id = $_POST["commercial_suivi_id"];
- $contrat->commercial_signature_id = $_POST["commercial_signature_id"];
+ $object->note = trim($_POST["note"]);
+ $object->fk_project = trim($_POST["projectid"]);
+ $object->remise_percent = trim($_POST["remise_percent"]);
+ $object->ref = trim($_POST["ref"]);
- $contrat->note = trim($_POST["note"]);
- $contrat->fk_project = trim($_POST["projectid"]);
- $contrat->remise_percent = trim($_POST["remise_percent"]);
- $contrat->ref = trim($_POST["ref"]);
-
- $result = $contrat->create($user,$langs,$conf);
+ $result = $object->create($user,$langs,$conf);
if ($result > 0)
{
- Header("Location: fiche.php?id=".$contrat->id);
+ Header("Location: fiche.php?id=".$object->id);
exit;
}
else {
- $mesg='
'.$contrat->error.'
';
+ $mesg=''.$object->error.'
';
}
$_GET["socid"]=$_POST["socid"];
$_GET["action"]='create';
@@ -175,23 +173,21 @@ if ($_POST["action"] == 'add')
if ($_POST["action"] == 'classin')
{
- $contrat = new Contrat($db);
- $contrat->fetch($_GET["id"]);
- $contrat->setProject($_POST["projectid"]);
+ $object->fetch($_GET["id"]);
+ $object->setProject($_POST["projectid"]);
}
if ($_POST["action"] == 'addline' && $user->rights->contrat->creer)
{
if ($_POST["pqty"] && (($_POST["pu"] != '' && $_POST["desc"]) || $_POST["idprod"]))
{
- $contrat = new Contrat($db);
- $ret=$contrat->fetch($_GET["id"]);
+ $ret=$object->fetch($_GET["id"]);
if ($ret < 0)
{
dol_print_error($db,$commande->error);
exit;
}
- $ret=$contrat->fetch_thirdparty();
+ $ret=$object->fetch_thirdparty();
$date_start='';
$date_end='';
@@ -229,16 +225,16 @@ if ($_POST["action"] == 'addline' && $user->rights->contrat->creer)
$prod = new Product($db, $_POST['idprod']);
$prod->fetch($_POST['idprod']);
- $tva_tx = get_default_tva($mysoc,$contrat->client,$prod->id);
- $tva_npr = get_default_npr($mysoc,$contrat->client,$prod->id);
+ $tva_tx = get_default_tva($mysoc,$object->client,$prod->id);
+ $tva_npr = get_default_npr($mysoc,$object->client,$prod->id);
// On defini prix unitaire
- if ($conf->global->PRODUIT_MULTIPRICES && $contrat->client->price_level)
+ if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level)
{
- $pu_ht = $prod->multiprices[$contrat->client->price_level];
- $pu_ttc = $prod->multiprices_ttc[$contrat->client->price_level];
- $price_min = $prod->multiprices_min[$contrat->client->price_level];
- $price_base_type = $prod->multiprices_base_type[$contrat->client->price_level];
+ $pu_ht = $prod->multiprices[$object->client->price_level];
+ $pu_ttc = $prod->multiprices_ttc[$object->client->price_level];
+ $price_min = $prod->multiprices_min[$object->client->price_level];
+ $price_base_type = $prod->multiprices_base_type[$object->client->price_level];
}
else
{
@@ -275,21 +271,21 @@ if ($_POST["action"] == 'addline' && $user->rights->contrat->creer)
$desc=$_POST['desc'];
}
- $localtax1_tx=get_localtax($tva_tx,1,$contrat->client);
- $localtax2_tx=get_localtax($tva_tx,2,$contrat->client);
+ $localtax1_tx=get_localtax($tva_tx,1,$object->client);
+ $localtax2_tx=get_localtax($tva_tx,2,$object->client);
$info_bits=0;
if ($tva_npr) $info_bits |= 0x01;
if($price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($price_min)))
{
- $contrat->error = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)) ;
+ $object->error = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->monnaie)) ;
$result = -1 ;
}
else
{
// Insert line
- $result = $contrat->addline(
+ $result = $object->addline(
$desc,
$pu_ht,
$_POST["pqty"],
@@ -313,52 +309,52 @@ if ($_POST["action"] == 'addline' && $user->rights->contrat->creer)
$outputlangs = $langs;
$newlang='';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
- if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$contrat->client->default_lang;
+ if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
- contrat_pdf_create($db, $contrat->id, $contrat->modelpdf, $outputlangs);
+ contrat_pdf_create($db, $object->id, $object->modelpdf, $outputlangs);
*/
}
else
{
- $mesg=''.$contrat->error.'
';
+ $mesg=''.$object->error.'
';
}
}
}
if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer && ! $_POST["cancel"])
{
- $contratline = new ContratLigne($db);
- if ($contratline->fetch($_POST["elrowid"]))
+ $objectline = new ContratLigne($db);
+ if ($objectline->fetch($_POST["elrowid"]))
{
$db->begin();
- if ($date_start_real_update == '') $date_start_real_update=$contratline->date_ouverture;
- if ($date_end_real_update == '') $date_end_real_update=$contratline->date_cloture;
+ if ($date_start_real_update == '') $date_start_real_update=$objectline->date_ouverture;
+ if ($date_end_real_update == '') $date_end_real_update=$objectline->date_cloture;
- $localtax1_tx=get_localtax($_POST["eltva_tx"],1,$contrat->client);
- $localtax2_tx=get_localtax($_POST["eltva_tx"],2,$contrat->client);
+ $localtax1_tx=get_localtax($_POST["eltva_tx"],1,$object->client);
+ $localtax2_tx=get_localtax($_POST["eltva_tx"],2,$object->client);
- $contratline->description=$_POST["eldesc"];
- $contratline->price_ht=$_POST["elprice"];
- $contratline->subprice=$_POST["elprice"];
- $contratline->qty=$_POST["elqty"];
- $contratline->remise_percent=$_POST["elremise_percent"];
- $contratline->tva_tx=$_POST["eltva_tx"];
- $contratline->localtax1_tx=$localtax1_tx;
- $contratline->localtax2_tx=$localtax2_tx;
- $contratline->date_ouverture_prevue=$date_start_update;
- $contratline->date_ouverture=$date_start_real_update;
- $contratline->date_fin_validite=$date_end_update;
- $contratline->date_cloture=$date_end_real_update;
- $contratline->fk_user_cloture=$user->id;
+ $objectline->description=$_POST["eldesc"];
+ $objectline->price_ht=$_POST["elprice"];
+ $objectline->subprice=$_POST["elprice"];
+ $objectline->qty=$_POST["elqty"];
+ $objectline->remise_percent=$_POST["elremise_percent"];
+ $objectline->tva_tx=$_POST["eltva_tx"];
+ $objectline->localtax1_tx=$localtax1_tx;
+ $objectline->localtax2_tx=$localtax2_tx;
+ $objectline->date_ouverture_prevue=$date_start_update;
+ $objectline->date_ouverture=$date_start_real_update;
+ $objectline->date_fin_validite=$date_end_update;
+ $objectline->date_cloture=$date_end_real_update;
+ $objectline->fk_user_cloture=$user->id;
// TODO verifier price_min si fk_product et multiprix
- $result=$contratline->update($user);
+ $result=$objectline->update($user);
if ($result > 0)
{
$db->commit();
@@ -377,43 +373,39 @@ if ($_POST["action"] == 'updateligne' && $user->rights->contrat->creer && ! $_PO
if ($_REQUEST["action"] == 'confirm_deleteline' && $_REQUEST["confirm"] == 'yes' && $user->rights->contrat->creer)
{
- $contrat = new Contrat($db);
- $contrat->fetch($_GET["id"]);
- $result = $contrat->deleteline($_GET["lineid"],$user);
+ $object->fetch($_GET["id"]);
+ $result = $object->deleteline($_GET["lineid"],$user);
if ($result >= 0)
{
- Header("Location: fiche.php?id=".$contrat->id);
+ Header("Location: fiche.php?id=".$object->id);
exit;
}
else
{
- $mesg=$contrat->error;
+ $mesg=$object->error;
}
}
if ($_REQUEST["action"] == 'confirm_valid' && $_REQUEST["confirm"] == 'yes' && $user->rights->contrat->creer)
{
- $contrat = new Contrat($db);
- $contrat->fetch($_GET["id"]);
- $result = $contrat->validate($user,$langs,$conf);
+ $object->fetch($_GET["id"]);
+ $result = $object->validate($user,$langs,$conf);
}
// Close all lines
if ($_REQUEST["action"] == 'confirm_close' && $_REQUEST["confirm"] == 'yes' && $user->rights->contrat->creer)
{
- $contrat = new Contrat($db);
- $contrat->fetch($_GET["id"]);
- $result = $contrat->cloture($user,$langs,$conf);
+ $object->fetch($_GET["id"]);
+ $result = $object->cloture($user,$langs,$conf);
}
if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes')
{
if ($user->rights->contrat->supprimer)
{
- $contrat = new Contrat($db);
- $contrat->id = $_GET["id"];
- $result=$contrat->delete($user,$langs,$conf);
+ $object->id = $_GET["id"];
+ $result=$object->delete($user,$langs,$conf);
if ($result >= 0)
{
Header("Location: index.php");
@@ -421,7 +413,7 @@ if ($_REQUEST["action"] == 'confirm_delete' && $_REQUEST["confirm"] == 'yes')
}
else
{
- $mesg=''.$contrat->error.'
';
+ $mesg=''.$object->error.'
';
}
}
}
@@ -443,7 +435,7 @@ if ($_REQUEST["action"] == 'confirm_move' && $_REQUEST["confirm"] == 'yes')
}
else
{
- $mesg=''.$contrat->error.'
';
+ $mesg=''.$object->error.'
';
}
}
else
@@ -463,7 +455,7 @@ llxHeader('',$langs->trans("ContractCard"),"Contrat");
$form = new Form($db);
$html = new Form($db);
-$contratlignestatic=new ContratLigne($db);
+$objectlignestatic=new ContratLigne($db);
/*********************************************************************
@@ -480,11 +472,10 @@ if ($_GET["action"] == 'create')
$soc = new Societe($db);
$soc->fetch($socid);
- $contract = new Contrat($db);
- $contract->date_contrat = time();
- if ($contratid) $result=$contract->fetch($contratid);
+ $object->date_contrat = time();
+ if ($contratid) $result=$object->fetch($contratid);
- $numct = $contract->getNextNumRef($soc);
+ $numct = $object->getNextNumRef($soc);
print '';
}
@@ -775,7 +765,7 @@ else
$servicepos=(isset($_REQUEST["servicepos"])?$_REQUEST["servicepos"]:1);
$colorb='666666';
- $arrayothercontracts=$contrat->getListOfContracts('others');
+ $arrayothercontracts=$object->getListOfContracts('others');
/*
* Lines of contracts
@@ -803,7 +793,7 @@ else
$sql.= " p.ref, p.label";
$sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
- $sql.= " WHERE cd.rowid = ".$contrat->lines[$cursorline-1]->id;
+ $sql.= " WHERE cd.rowid = ".$object->lines[$cursorline-1]->id;
$result = $db->query($sql);
if ($result)
@@ -859,28 +849,28 @@ else
}
// Icon move, update et delete (statut contrat 0=brouillon,1=valide,2=ferme)
print '';
- if ($user->rights->contrat->creer && sizeof($arrayothercontracts) && ($contrat->statut >= 0))
+ if ($user->rights->contrat->creer && sizeof($arrayothercontracts) && ($object->statut >= 0))
{
- print '';
+ print '';
print img_picto($langs->trans("MoveToAnotherContract"),'uparrow');
print '';
}
else {
print ' ';
}
- if ($user->rights->contrat->creer && ($contrat->statut >= 0))
+ if ($user->rights->contrat->creer && ($object->statut >= 0))
{
- print '';
+ print '';
print img_edit();
print '';
}
else {
print ' ';
}
- if ( $user->rights->contrat->creer && ($contrat->statut >= 0))
+ if ( $user->rights->contrat->creer && ($object->statut >= 0))
{
print ' ';
- print '';
+ print '';
print img_delete();
print '';
}
@@ -939,7 +929,7 @@ else
}
print ' | ';
print '';
- print $form->select_tva("eltva_tx",$objp->tva_tx,$mysoc,$contrat->societe);
+ print $form->select_tva("eltva_tx",$objp->tva_tx,$mysoc,$object->societe);
print ' | ';
print ' | ';
print ' | ';
@@ -967,7 +957,7 @@ else
dol_print_error($db);
}
- if ($contrat->statut > 0)
+ if ($object->statut > 0)
{
print '';
print '
| ';
@@ -980,16 +970,16 @@ else
/*
* Confirmation to delete service line of contract
*/
- if ($_REQUEST["action"] == 'deleteline' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $contrat->lines[$cursorline-1]->id == $_GET["rowid"])
+ if ($_REQUEST["action"] == 'deleteline' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline-1]->id == $_GET["rowid"])
{
- $ret=$html->form_confirm($_SERVER["PHP_SELF"]."?id=".$contrat->id."&lineid=".$_GET["rowid"],$langs->trans("DeleteContractLine"),$langs->trans("ConfirmDeleteContractLine"),"confirm_deleteline",'',0,1);
+ $ret=$html->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".$_GET["rowid"],$langs->trans("DeleteContractLine"),$langs->trans("ConfirmDeleteContractLine"),"confirm_deleteline",'',0,1);
if ($ret == 'html') print '';
}
/*
* Confirmation to move service toward another contract
*/
- if ($_REQUEST["action"] == 'move' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $contrat->lines[$cursorline-1]->id == $_GET["rowid"])
+ if ($_REQUEST["action"] == 'move' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline-1]->id == $_GET["rowid"])
{
$arraycontractid=array();
foreach($arrayothercontracts as $contractcursor)
@@ -1002,50 +992,50 @@ else
'text' => $langs->trans("ConfirmMoveToAnotherContractQuestion"),
array('type' => 'select', 'name' => 'newcid', 'values' => $arraycontractid));
- $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$contrat->id."&lineid=".$_GET["rowid"],$langs->trans("MoveToAnotherContract"),$langs->trans("ConfirmMoveToAnotherContract"),"confirm_move",$formquestion);
+ $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".$_GET["rowid"],$langs->trans("MoveToAnotherContract"),$langs->trans("ConfirmMoveToAnotherContract"),"confirm_move",$formquestion);
print '';
}
/*
* Confirmation de la validation activation
*/
- if ($_REQUEST["action"] == 'active' && ! $_REQUEST["cancel"] && $user->rights->contrat->activer && $contrat->lines[$cursorline-1]->id == $_GET["ligne"])
+ if ($_REQUEST["action"] == 'active' && ! $_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline-1]->id == $_GET["ligne"])
{
$dateactstart = dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
$dateactend = dol_mktime(12, 0 , 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]);
$comment = $_POST["comment"];
- $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$contrat->id."&ligne=".$_GET["ligne"]."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment),$langs->trans("ActivateService"),$langs->trans("ConfirmActivateService",dol_print_date($dateactstart,"%A %d %B %Y")),"confirm_active", '', 0, 1);
+ $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".$_GET["ligne"]."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment),$langs->trans("ActivateService"),$langs->trans("ConfirmActivateService",dol_print_date($dateactstart,"%A %d %B %Y")),"confirm_active", '', 0, 1);
print '';
}
/*
* Confirmation de la validation fermeture
*/
- if ($_REQUEST["action"] == 'closeline' && ! $_REQUEST["cancel"] && $user->rights->contrat->activer && $contrat->lines[$cursorline-1]->id == $_GET["ligne"])
+ if ($_REQUEST["action"] == 'closeline' && ! $_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline-1]->id == $_GET["ligne"])
{
$dateactstart = dol_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
$dateactend = dol_mktime(12, 0 , 0, $_POST["endmonth"], $_POST["endday"], $_POST["endyear"]);
$comment = $_POST["comment"];
- $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$contrat->id."&ligne=".$_GET["ligne"]."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("CloseService"), $langs->trans("ConfirmCloseService",dol_print_date($dateactend,"%A %d %B %Y")), "confirm_closeline", '', 0, 1);
+ $html->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".$_GET["ligne"]."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("CloseService"), $langs->trans("ConfirmCloseService",dol_print_date($dateactend,"%A %d %B %Y")), "confirm_closeline", '', 0, 1);
print '';
}
// Area with status and activation info of line
- if ($contrat->statut > 0)
+ if ($object->statut > 0)
{
print '';
}
- if ($user->rights->contrat->activer && $_REQUEST["action"] == 'activateline' && $contrat->lines[$cursorline-1]->id == $_GET["ligne"])
+ if ($user->rights->contrat->activer && $_REQUEST["action"] == 'activateline' && $object->lines[$cursorline-1]->id == $_GET["ligne"])
{
/**
* Activer la ligne de contrat
*/
- print '