<commit_before><?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * This file is part of Onlogistics, a web based ERP and supply chain 
 * management application. 
 *
 * Copyright (C) 2003-2008 ATEOR
 *
 * This program is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU Affero 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 Affero General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * PHP version 5.1.0+
 *
 * @package   Onlogistics
 * @author    ATEOR dev team <<EMAIL>>
 * @copyright 2003-2008 ATEOR <<EMAIL>> 
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU AGPL
 * @version   SVN: $Id$
 * @link      http://www.onlogistics.org
 * @link      http://onlogistics.googlecode.com
 * @since     File available since release 0.1.0
 * @filesource
 */

require_once('config.inc.php');
require_once('lib/Objects/MovementType.const.php');
require_once('ExecutedMovementTools.php');
require_once('lib/Objects/Actor.inc.php');
// }}}
// sessions + auth {{{
$session = Session::singleton();
$auth = Auth::Singleton();
$auth->checkProfiles(array(
    UserAccount::PROFILE_ADMIN, UserAccount::PROFILE_ADMIN_WITHOUT_CASHFLOW, 
    UserAccount::PROFILE_GESTIONNAIRE_STOCK, UserAccount::PROFILE_OPERATOR,
    UserAccount::PROFILE_TRANSPORTEUR));

$lemIDs = SearchTools::requestOrSessionExist('lemIDs');
// }}}
// impression du BE {{{
if(isset($_REQUEST['print']) && $_REQUEST['print']==1) {
    if(isset($_REQUEST['showMsg']) && $_REQUEST['showMsg']==1) {
        Template::infoDialog(_('The document was created.'), 
            'ForwardingFormEdit.php?print=1&doc=' . $_REQUEST['doc'],
            BASE_POPUP_TEMPLATE);
        exit();
    }
    if (!isset($_REQUEST['doc'])) {
        Template::errorDialog(E_MSG_TRY_AGAIN, 'javascript:window.close()', 
            BASE_POPUP_TEMPLATE);
    	exit();
    }
    $forwardingForm = Object::load('ForwardingForm', $_REQUEST['doc']);
    if (!($forwardingForm instanceof ForwardingForm)) {
        Template::errorDialog(E_MSG_TRY_AGAIN, 'javascript:window.close()', 
            BASE_POPUP_TEMPLATE);
    	exit();
    }
    require_once('GenerateDocument.php');
    $reedit = isset($_REQUEST['reedit']) ? $_REQUEST['reedit'] : 0;
    generateDocument($forwardingForm, $reedit);
    exit();
}
// }}}
// cration du BE {{{
if (isset($_REQUEST['FormSubmitted']) && $_REQUEST['FormSubmitted'] == 'true') {
    // si pas de lem, inutile d'aller plus loin
    if(!$lemIDs) {
        Template::errorDialog(E_MSG_TRY_AGAIN, 
            'javascript:window.close()', BASE_POPUP_TEMPLATE);
        exit();
    }
    require_once('InvoiceItemTools.php');
    Database::connection()->startTrans();
    // recherche du supplier customer {{{
    if(!isset($_SESSION['supplierCustomer'])) {
        $supCust = Object::load('SupplierCustomer', array(
            'Supplier'=>$auth->getActorId(),
            'Customer'=>$_POST['cmdDestinator']));
        if (!($supCust instanceof SupplierCustomer)) {
            $customer = Object::load('Actor', $_POST['cmdDestinator']);
            $supCust = Object::load('SupplierCustomer');
            $supCust->setSupplier($auth->getActor());
            $supCust->setCustomer($customer);
        }
        $session->register('supplierCustomer', $supCust, 2);
    } else {
        $supCust = $_SESSION['supplierCustomer'];
    }
    // }}}
    // cration du ForwardingForm {{{
    if(!isset($_SESSION['forwardingForm'])) {
        $forwardingForm = Object::load('ForwardingForm');
        $forwardingForm->setEditionDate(date('Y-m-d H:i:s'));
        $forwardingForm->setCommandNo($_POST['CommandNo']);
        $forwardingForm->setTransporter($_POST['Transporter']);
        $forwardingForm->setConveyorDepartureSite($_POST['ConveyorDepartureSite']);
        $forwardingForm->setConveyorArrivalSite($_POST['ConveyorArrivalSite']);
        $forwardingForm->setSupplierCustomer($supCust);
        $forwardingForm->setDestinatorSite($_POST['cmdDestinatorSite']);
        $forwardingForm->setDocumentModel($forwardingForm->findDocumentModel());

        $session->register('forwardingForm', $forwardingForm, 2);
    } else {
        $forwardingForm = $_SESSION['forwardingForm'];
    }
    $forwardingForm->setDocumentNo(
        generateDocumentNo('BE', 'ForwardingForm', $forwardingForm->generateId()));
    // }}}
    // cration des ForwardingFormPacking  partir des Product {{{
    if(isset($_POST['Product_ID']) && (!isset($_REQUEST['force']) || !$_REQUEST['force'])) {
        $date = date('Y-m-d H:i:s');
        // recherche de l'emplacement de destination des pdt consign {{{
        $site = $forwardingForm->getConveyorArrivalSite();
        $site = $site instanceof Site ? $site : $_POST['cmdDestinatorSite'];
        $locationCol = Object::loadCollection('Location',
            array('Store.StorageSite' => $site));
        if($locationCol->getCount() == 0) {
            Template::confirmDialog(
                _('No location was found for this addressee, deposited packings will not be taken into account, continue ?'),
                $_SERVER['PHP_SELF'] . '?FormSubmitted=true&force=1',
                $_SERVER['PHP_SELF'], BASE_POPUP_TEMPLATE);
            exit();
        }
        $locationEntry = $locationCol->getItem(0);
        // }}}
        // cration des ForwardingFormPacking et des mouvements {{{
        foreach($_POST['Product'] as $key=>$pdtId) {
            // cration ForwardingFormPacking {{{
            $product = Object::load('Product', $pdtId);
            $TotalQty = 0;
            if (isset($_POST['ProductQty']) && is_array($_POST['ProductQty'])) {
                foreach($_POST['ProductQty'][$key] as $qty) {
                    $TotalQty += $qty;
                }
            }
            $o = new ForwardingFormPacking();
            $o->setProduct($product);
            $o->setCoverType(0);
            $o->setQuantity($TotalQty);
            $o->setForwardingForm($forwardingForm);
            saveInstance($o, 'javascript:window.close()');
            // }}}
            // cration exm de sortie {{{
            $EXM_Out = new ExecutedMovement();
            $EXM_Out->setStartDate($date);
            $EXM_Out->setEndDate($date);
            $EXM_Out->setRealProduct($product);
            $EXM_Out->setState(ExecutedMovement::EXECUTE_TOTALEMENT);
            $EXM_Out->setType(SORTIE_DEPLACEMT);
            $EXM_Out->setRealQuantity($TotalQty);
            $EXM_Out->setProductVirtualQuantity();
            saveInstance($EXM_Out, 'javascript:window.close()');
            // }}}
            // cration exm d'entr {{{
            $EXM_In = new ExecutedMovement();
            $EXM_In->setStartDate($date);
            $EXM_In->setEndDate($date);
            $EXM_In->setRealProduct($product);
            $EXM_In->setState(ExecutedMovement::EXECUTE_TOTALEMENT);
            $EXM_In->setType(ENTREE_DEPLACEMT);
            $EXM_In->setRealQuantity($TotalQty);
            $EXM_In->setProductVirtualQuantity();
            saveInstance($EXM_In, 'javascript:window.close()');
            // }}}
            // cration des lem de sortie et d'entre, maj des lpq {{{
            foreach($_POST['ProductLocation'][$key] as $index=>$locationExit) {
                $qty = $_POST['ProductQty'][$key][$index];
                if($qty==0) {<commit_msg>make sure that $_POST["Productlocation"] is set<commit_after><?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */

/**
 * This file is part of Onlogistics, a web based ERP and supply chain 
 * management application. 
 *
 * Copyright (C) 2003-2008 ATEOR
 *
 * This program is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU Affero 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 Affero General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * PHP version 5.1.0+
 *
 * @package   Onlogistics
 * @author    ATEOR dev team <<EMAIL>>
 * @copyright 2003-2008 ATEOR <<EMAIL>> 
 * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU AGPL
 * @version   SVN: $Id$
 * @link      http://www.onlogistics.org
 * @link      http://onlogistics.googlecode.com
 * @since     File available since release 0.1.0
 * @filesource
 */

require_once('config.inc.php');
require_once('lib/Objects/MovementType.const.php');
require_once('ExecutedMovementTools.php');
require_once('lib/Objects/Actor.inc.php');
// }}}
// sessions + auth {{{
$session = Session::singleton();
$auth = Auth::Singleton();
$auth->checkProfiles(array(
    UserAccount::PROFILE_ADMIN, UserAccount::PROFILE_ADMIN_WITHOUT_CASHFLOW, 
    UserAccount::PROFILE_GESTIONNAIRE_STOCK, UserAccount::PROFILE_OPERATOR,
    UserAccount::PROFILE_TRANSPORTEUR));

$lemIDs = SearchTools::requestOrSessionExist('lemIDs');
// }}}
// impression du BE {{{
if(isset($_REQUEST['print']) && $_REQUEST['print']==1) {
    if(isset($_REQUEST['showMsg']) && $_REQUEST['showMsg']==1) {
        Template::infoDialog(_('The document was created.'), 
            'ForwardingFormEdit.php?print=1&doc=' . $_REQUEST['doc'],
            BASE_POPUP_TEMPLATE);
        exit();
    }
    if (!isset($_REQUEST['doc'])) {
        Template::errorDialog(E_MSG_TRY_AGAIN, 'javascript:window.close()', 
            BASE_POPUP_TEMPLATE);
    	exit();
    }
    $forwardingForm = Object::load('ForwardingForm', $_REQUEST['doc']);
    if (!($forwardingForm instanceof ForwardingForm)) {
        Template::errorDialog(E_MSG_TRY_AGAIN, 'javascript:window.close()', 
            BASE_POPUP_TEMPLATE);
    	exit();
    }
    require_once('GenerateDocument.php');
    $reedit = isset($_REQUEST['reedit']) ? $_REQUEST['reedit'] : 0;
    generateDocument($forwardingForm, $reedit);
    exit();
}
// }}}
// cration du BE {{{
if (isset($_REQUEST['FormSubmitted']) && $_REQUEST['FormSubmitted'] == 'true') {
    // si pas de lem, inutile d'aller plus loin
    if(!$lemIDs) {
        Template::errorDialog(E_MSG_TRY_AGAIN, 
            'javascript:window.close()', BASE_POPUP_TEMPLATE);
        exit();
    }
    require_once('InvoiceItemTools.php');
    Database::connection()->startTrans();
    // recherche du supplier customer {{{
    if(!isset($_SESSION['supplierCustomer'])) {
        $supCust = Object::load('SupplierCustomer', array(
            'Supplier'=>$auth->getActorId(),
            'Customer'=>$_POST['cmdDestinator']));
        if (!($supCust instanceof SupplierCustomer)) {
            $customer = Object::load('Actor', $_POST['cmdDestinator']);
            $supCust = Object::load('SupplierCustomer');
            $supCust->setSupplier($auth->getActor());
            $supCust->setCustomer($customer);
        }
        $session->register('supplierCustomer', $supCust, 2);
    } else {
        $supCust = $_SESSION['supplierCustomer'];
    }
    // }}}
    // cration du ForwardingForm {{{
    if(!isset($_SESSION['forwardingForm'])) {
        $forwardingForm = Object::load('ForwardingForm');
        $forwardingForm->setEditionDate(date('Y-m-d H:i:s'));
        $forwardingForm->setCommandNo($_POST['CommandNo']);
        $forwardingForm->setTransporter($_POST['Transporter']);
        $forwardingForm->setConveyorDepartureSite($_POST['ConveyorDepartureSite']);
        $forwardingForm->setConveyorArrivalSite($_POST['ConveyorArrivalSite']);
        $forwardingForm->setSupplierCustomer($supCust);
        $forwardingForm->setDestinatorSite($_POST['cmdDestinatorSite']);
        $forwardingForm->setDocumentModel($forwardingForm->findDocumentModel());

        $session->register('forwardingForm', $forwardingForm, 2);
    } else {
        $forwardingForm = $_SESSION['forwardingForm'];
    }
    $forwardingForm->setDocumentNo(
        generateDocumentNo('BE', 'ForwardingForm', $forwardingForm->generateId()));
    // }}}
    // cration des ForwardingFormPacking  partir des Product {{{
    if(isset($_POST['Product_ID']) && (!isset($_REQUEST['force']) || !$_REQUEST['force'])) {
        $date = date('Y-m-d H:i:s');
        // recherche de l'emplacement de destination des pdt consign {{{
        $site = $forwardingForm->getConveyorArrivalSite();
        $site = $site instanceof Site ? $site : $_POST['cmdDestinatorSite'];
        $locationCol = Object::loadCollection('Location',
            array('Store.StorageSite' => $site));
        if($locationCol->getCount() == 0) {
            Template::confirmDialog(
                _('No location was found for this addressee, deposited packings will not be taken into account, continue ?'),
                $_SERVER['PHP_SELF'] . '?FormSubmitted=true&force=1',
                $_SERVER['PHP_SELF'], BASE_POPUP_TEMPLATE);
            exit();
        }
        $locationEntry = $locationCol->getItem(0);
        // }}}
        // cration des ForwardingFormPacking et des mouvements {{{
        foreach($_POST['Product'] as $key=>$pdtId) {
            // cration ForwardingFormPacking {{{
            $product = Object::load('Product', $pdtId);
            $TotalQty = 0;
            if (isset($_POST['ProductQty']) && is_array($_POST['ProductQty'])) {
                foreach($_POST['ProductQty'][$key] as $qty) {
                    $TotalQty += $qty;
                }
            }
            $o = new ForwardingFormPacking();
            $o->setProduct($product);
            $o->setCoverType(0);
            $o->setQuantity($TotalQty);
            $o->setForwardingForm($forwardingForm);
            saveInstance($o, 'javascript:window.close()');
            // }}}
            // cration exm de sortie {{{
            $EXM_Out = new ExecutedMovement();
            $EXM_Out->setStartDate($date);
            $EXM_Out->setEndDate($date);
            $EXM_Out->setRealProduct($product);
            $EXM_Out->setState(ExecutedMovement::EXECUTE_TOTALEMENT);
            $EXM_Out->setType(SORTIE_DEPLACEMT);
            $EXM_Out->setRealQuantity($TotalQty);
            $EXM_Out->setProductVirtualQuantity();
            saveInstance($EXM_Out, 'javascript:window.close()');
            // }}}
            // cration exm d'entr {{{
            $EXM_In = new ExecutedMovement();
            $EXM_In->setStartDate($date);
            $EXM_In->setEndDate($date);
            $EXM_In->setRealProduct($product);
            $EXM_In->setState(ExecutedMovement::EXECUTE_TOTALEMENT);
            $EXM_In->setType(ENTREE_DEPLACEMT);
            $EXM_In->setRealQuantity($TotalQty);
            $EXM_In->setProductVirtualQuantity();
            saveInstance($EXM_In, 'javascript:window.close()');
            // }}}
            // cration des lem de sortie et d'entre, maj des lpq {{{
            if (!isset($_POST['ProductLocation']) || !is_array($_POST['ProductLocation'])) {
                continue;
            }
            foreach($_POST['ProductLocation'][$key] as $index=>$locationExit) {
                $qty = $_POST['ProductQty'][$key][$index];
                if($qty==0) {
{'fraction_non_alphanumeric': 0.15441223117426886, 'fraction_numerical': 0.005075176045169067, 'mean_word_length': 2.9959442332065906, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6849315', 'n_tokens_mistral': 4808, 'n_tokens_neox': 4682, 'n_words': 869}