New: Can move a line of contract to another.

This commit is contained in:
Laurent Destailleur 2008-09-25 23:30:06 +00:00
parent b866f3c477
commit 047ec077cc
6 changed files with 119 additions and 19 deletions

View File

@ -8,6 +8,7 @@ For users:
- Look enhancements for graphics (add transparency).
- Added statistics report for supplier invoices
- Added average amount in invoices statistics reports.
- Can move a contract line to another contract of same third party.
For translators:
- The errors language file contains only error or warning messages with

View File

@ -1117,11 +1117,10 @@ class Contrat extends CommonObject
}
}
/**
* \brief R<EFBFBD>cup<EFBFBD>re les lignes de detail du contrat
* \param statut Statut des lignes detail <EFBFBD> r<EFBFBD>cup<EFBFBD>rer
* \return array Tableau des lignes de details
/**
* \brief Return list of line rowid
* \param statut Status of lines to get
* \return array Array of line's rowid
*/
function array_detail($statut=-1)
{
@ -1132,6 +1131,7 @@ class Contrat extends CommonObject
$sql.= " WHERE fk_contrat =".$this->id;
if ($statut >= 0) $sql.= " AND statut = '$statut'";
dolibarr_syslog("Contrat::array_detail() sql=".$sql,LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
@ -1151,12 +1151,49 @@ class Contrat extends CommonObject
return -1;
}
}
/**
* \brief Return list of other contracts for same company than current contract
* \param option 'all' or 'others'
* \return array Array of contracts id
*/
function getListOfContracts($option='all')
{
$tab=array();
$sql = "SELECT c.rowid, c.ref";
$sql.= " FROM ".MAIN_DB_PREFIX."contrat as c";
$sql.= " WHERE fk_soc =".$this->socid;
if ($option == 'others') $sql.= " AND c.rowid != ".$this->id;
dolibarr_syslog("Contrat::getOtherContracts() sql=".$sql,LOG_DEBUG);
$resql=$this->db->query($sql);
if ($resql)
{
$num=$this->db->num_rows($resql);
$i=0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
$contrat=new Contrat($this->db);
$contrat->fetch($obj->rowid);
$tab[]=$contrat;
$i++;
}
return $tab;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Charge indicateurs this->nbtodo et this->nbtodolate de tableau de bord
* \param user Objet user
* \param mode "inactive" pour services <EFBFBD> activer, "expired" pour services expir<EFBFBD>s
* \param mode "inactive" pour services a activer, "expired" pour services expires
* \return int <0 si ko, >0 si ok
*/
function load_board($user,$mode)
@ -1275,7 +1312,7 @@ class ContratLigne
/**
* \brief Constructeur d'objets ligne de contrat
* \param DB handler d'acc<EFBFBD>s base de donn<EFBFBD>e
* \param DB Database access handler
*/
function ContratLigne($DB)
{

View File

@ -131,10 +131,6 @@ if ($_POST["date_end_real_updatemonth"] && $_POST["date_end_real_updateday"] &&
$date_end_real_update=dolibarr_mktime(12, 0 , 0, $_POST["date_end_real_updatemonth"], $_POST["date_end_real_updateday"], $_POST["date_end_real_updateyear"]);
}
/*
* Actions
*/
if ($_POST["action"] == 'add')
{
$datecontrat = dolibarr_mktime(12, 0 , 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
@ -391,6 +387,32 @@ if ($_POST["action"] == 'confirm_delete' && $_POST["confirm"] == 'yes')
}
}
if ($_POST["action"] == 'confirm_move' && $_POST["confirm"] == 'yes')
{
if ($user->rights->contrat->creer)
{
if ($_POST['newcid'] > 0)
{
$contractline = new ContratLigne($db);
$result=$contractline->fetch($_GET["lineid"]);
$contractline->fk_contrat = $_POST["newcid"];
$result=$contractline->update($user,1);
if ($result >= 0)
{
Header("Location: ".$_SERVER['PHP_SELF'].'?id='.$_GET['id']);
return;
}
else
{
$mesg='<div class="error">'.$contrat->error.'</div>';
}
}
else
{
$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("RefNewContract")).'</div>';
}
}
}
/*
@ -716,7 +738,9 @@ else
$servicepos=(isset($_REQUEST["servicepos"])?$_REQUEST["servicepos"]:1);
$colorb='333333';
/*
$arrayothercontracts=$contrat->getListOfContracts('others');
/*
* Lignes de contrats
*/
@ -734,7 +758,7 @@ else
// Area with common detail of line
print '<table class="noborder" width="100%">';
$sql = "SELECT cd.statut, cd.label as label_det, cd.fk_product, cd.description, cd.price_ht, cd.qty, cd.rowid,";
$sql = "SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.description, cd.price_ht, cd.qty,";
$sql.= " cd.tva_tx, cd.remise_percent, cd.info_bits, cd.subprice,";
$sql.= " ".$db->pdate("cd.date_ouverture_prevue")." as date_debut, ".$db->pdate("cd.date_ouverture")." as date_debut_reelle,";
$sql.= " ".$db->pdate("cd.date_fin_validite")." as date_fin, ".$db->pdate("cd.date_cloture")." as date_fin_reelle,";
@ -795,8 +819,17 @@ else
{
print '<td>&nbsp;</td>';
}
// Icon update et delete (statut contrat 0=brouillon,1=valid<EFBFBD>,2=ferm<72>)
// Icon move, update et delete (statut contrat 0=brouillon,1=valid�,2=ferm�)
print '<td align="right" nowrap="nowrap">';
if (sizeof($arrayothercontracts) && $contrat->statut != 2 && $user->rights->contrat->creer)
{
print '<a href="fiche.php?id='.$id.'&amp;action=move&amp;rowid='.$objp->rowid.'">';
print img_picto($langs->trans("MoveToAnotherContract"),'uparrow');
print '</a>';
}
else {
print '&nbsp;';
}
if ($contrat->statut != 2 && $user->rights->contrat->creer)
{
print '<a href="fiche.php?id='.$id.'&amp;action=editline&amp;rowid='.$objp->rowid.'">';
@ -824,11 +857,11 @@ else
print '<tr '.$bc[$var].'>';
print '<td colspan="6">';
// Date pr<EFBFBD>vues
// Date planned
print $langs->trans("DateStartPlanned").': ';
if ($objp->date_debut) {
print dolibarr_print_date($objp->date_debut);
// Warning si date prevu pass<EFBFBD>e et pas en service
// Warning si date prevu passee et pas en service
if ($objp->statut == 0 && $objp->date_debut < time() - $conf->contrat->warning_delay) { print " ".img_warning($langs->trans("Late")); }
}
else print $langs->trans("Unknown");
@ -904,6 +937,27 @@ else
print "</table>";
/*
* Confirmation to move service toward another contract
*/
if ($_REQUEST["action"] == 'move' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $contrat->lignes[$cursorline-1]->id == $_GET["rowid"])
{
//print '<br />';
$arraycontractid=array();
foreach($arrayothercontracts as $contractcursor)
{
$arraycontractid[$contractcursor->id]=$contractcursor->ref;
}
//var_dump($arraycontractid);
// Crée un tableau formulaire
$formquestion=array(
'text' => $langs->trans("ConfirmMoveToAnotherContractQuestion"),
array('type' => 'select', 'name' => 'newcid', 'values' => $arraycontractid));
$html->form_confirm($_SERVER["PHP_SELF"]."?id=".$contrat->id."&amp;lineid=".$_GET["rowid"],$langs->trans("MoveToAnotherContract"),$langs->trans("ConfirmMoveToAnotherContract"),"confirm_move",$formquestion);
print '<table class="noborder" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
}
/*
* Confirmation de la validation activation
*/

View File

@ -1960,7 +1960,6 @@ class Form
* \param action action
* \param formquestion an array with forms complementary inputs
*/
function form_confirm($page, $title, $question, $action, $formquestion='')
{
global $langs;
@ -1987,7 +1986,9 @@ class Form
}
if ($input['type'] == 'select')
{
print '<tr><td valign="top">';
print $this->select_array($input['name'],$input['values'],'',1);
print '</td></tr>';
}
if ($input['type'] == 'checkbox')
{
@ -2910,6 +2911,7 @@ class Form
function select_array($htmlname, $array, $id='', $show_empty=0, $key_in_label=0, $value_as_key=0, $optionType=0, $option='', $translate=0)
{
global $langs;
// \TODO Simplify optionType and option (only one should be necessary)
if ($optionType == 1 && $option != '')
{
print '<select class="flat" name="'.$htmlname.'" '.$option.'>';
@ -2938,7 +2940,7 @@ class Form
if ($key_in_label)
{
$selectOptionValue = $key.' - '.($translate?$langs->trans($value):$value);
print $selectOptionValue;
print $selectOptionValue;
}
else
{

View File

@ -69,6 +69,9 @@ ServiceStatus=Status of service
DraftContracts=Drafts contracts
CloseRefusedBecauseOneServiceActive=Contract can't be closed as ther is at least one open service on it
CloseAllContracts=Close all contracts
MoveToAnotherContract=Move service into another contract.
ConfirmMoveToAnotherContract=I choosed new target contract and confirm I want to move this service into this contract.
ConfirmMoveToAnotherContractQuestion=Choose in which existing contract (of same third party), you want to move this service to ?
##### Types de contacts #####
TypeContact_contrat_internal_SALESREPSIGN=Sales representative signing contract
TypeContact_contrat_internal_SALESREPFOLL=Sales representative following-up contract

View File

@ -69,6 +69,9 @@ ServiceStatus=Statut du service
DraftContracts=Contrats brouillons
CloseRefusedBecauseOneServiceActive=Fermeture du contrat impossible car il y a au moins un service actif
CloseAllContracts=Tout clôturer
MoveToAnotherContract=Déplacer le service vers un autre contrat de ce tiers.
ConfirmMoveToAnotherContract=J'ai choisi le contrat cible et confirme le déplacement du service dans ce contrat.
ConfirmMoveToAnotherContractQuestion=Choisissez vers quel autre contrat de ce même tiers, vous voulez déplacer ce service ?
##### Types de contacts #####
TypeContact_contrat_internal_SALESREPSIGN=Commercial signataire du contrat
TypeContact_contrat_internal_SALESREPFOLL=Commercial suivi du contrat