<?php

///***************************** إعادة الجرد ********************///
//the global file operation
$do = isset($_GET['do']) ? $_GET['do'] : "";
if ($do != "printoperation")
    include("../public/impOpreation.php");

//global varable
global $showoutside;

//to check if the page from .htacess
//$showoutside = $_GET['sn'];
// get the config file
include_once("../public/config.php");

//here the db files that include in the file
include("../public/include_dao.php");
include_once("dailyentryfun.php");
//Productcat
require_once('../models/dao/ProductcatDAO.class.php');
require_once('../models/dto/Productcat.class.php');
require_once('../models/mysql/ProductcatMySqlDAO.class.php');
require_once('../models/mysql/ext/ProductcatMySqlExtDAO.class.php');
//Product
require_once('../models/dao/ProductDAO.class.php');
require_once('../models/dto/Product.class.php');
require_once('../models/mysql/ProductMySqlDAO.class.php');
require_once('../models/mysql/ext/ProductMySqlExtDAO.class.php');
//Storedetail
require_once('../models/dao/StoredetailDAO.class.php');
require_once('../models/dto/Storedetail.class.php');
require_once('../models/mysql/StoredetailMySqlDAO.class.php');
require_once('../models/mysql/ext/StoredetailMySqlExtDAO.class.php');
//Storereport
require_once('../models/dao/StorereportDAO.class.php');
require_once('../models/dto/Storereport.class.php');
require_once('../models/mysql/StorereportMySqlDAO.class.php');
require_once('../models/mysql/ext/StorereportMySqlExtDAO.class.php');
//Unit
require_once('../models/dao/UnitDAO.class.php');
require_once('../models/dto/Unit.class.php');
require_once('../models/mysql/UnitMySqlDAO.class.php');
require_once('../models/mysql/ext/UnitMySqlExtDAO.class.php');
//Productunit
require_once('../models/dao/ProductunitDAO.class.php');
require_once('../models/dto/Productunit.class.php');
require_once('../models/mysql/ProductunitMySqlDAO.class.php');
require_once('../models/mysql/ext/ProductunitMySqlExtDAO.class.php');
//Store
require_once('../models/dao/StoreDAO.class.php');
require_once('../models/dto/Store.class.php');
require_once('../models/mysql/StoreMySqlDAO.class.php');
require_once('../models/mysql/ext/StoreMySqlExtDAO.class.php');
//Productcatunit
require_once('../models/dao/ProductcatunitDAO.class.php');
require_once('../models/dto/Productcatunit.class.php');
require_once('../models/mysql/ProductcatunitMySqlDAO.class.php');
require_once('../models/mysql/ext/ProductcatunitMySqlExtDAO.class.php');

require_once('../models/dao/RestaurantrawdestructionDAO.class.php');
require_once('../models/dto/Restaurantrawdestruction.class.php');
require_once('../models/mysql/RestaurantrawdestructionMySqlDAO.class.php');
require_once('../models/mysql/ext/RestaurantrawdestructionMySqlExtDAO.class.php');
//Programsetting
require_once('../models/dao/ProgramsettingsDAO.class.php');
require_once('../models/dto/Programsetting.class.php');
require_once('../models/mysql/ProgramsettingsMySqlDAO.class.php');
require_once('../models/mysql/ext/ProgramsettingsMySqlExtDAO.class.php');

require_once('../models/dao/YoutubeLinkDAO.class.php');
require_once('../models/dto/YoutubeLink.class.php');
require_once('../models/mysql/YoutubeLinkMySqlDAO.class.php');
require_once('../models/mysql/ext/YoutubeLinkMySqlExtDAO.class.php');
//Usergroup
require_once ('../models/dao/UsergroupDAO.class.php');
require_once ('../models/dto/Usergroup.class.php');
require_once ('../models/mysql/UsergroupMySqlDAO.class.php');
require_once ('../models/mysql/ext/UsergroupMySqlExtDAO.class.php');
//
require_once ('../models/dao/SizecolorstoredetailDAO.class.php');
require_once ('../models/dto/Sizecolorstoredetail.class.php');
require_once ('../models/mysql/SizecolorstoredetailMySqlDAO.class.php');
require_once ('../models/mysql/ext/SizecolorstoredetailMySqlExtDAO.class.php');

//get the do the action
$do = $_GET['do'];

/* ======================

  Controller Name :- restaurantRawDestructionController

  OPERTATION in Controller

  1- show products with store id or product category id or product id
  2- update product quantity

  ======================== */

//here the global templates
if ($do != "printoperation")
    $smarty->display("header.html");

//here goes the instances and general variables
//Productcat
$productCat = new Productcat();
$productCatDAO = new ProductcatMySqlDAO();
$productCatExt = new ProductcatMySqlExtDAO();
//Product
$product = new Product();
$productDAO = new ProductMySqlDAO();
$productExt = new ProductMySqlExtDAO();
//Storedetail
$storeDetail = new Storedetail();
$storeDetailDAO = new StoredetailMySqlDAO();
$storeDetailExt = new StoredetailMySqlExtDAO();
//Storereport
$storeReport = new Storereport();
$storeReportDAO = new StorereportMySqlDAO();
//Unit
$unitDAO = new UnitMySqlDAO();
$unitExt = new UnitMySqlExtDAO();
//Productunit
$productUnit = new Productunit();
$productUnitDAO = new ProductunitMySqlDAO();
$productUnitExt = new ProductunitMySqlExtDAO();
//Store
$storeDAO = new StoreMySqlDAO();
$myStoreEx = new StoreMySqlExtDAO();

//Unit
$unitDAO = new UnitMySqlDAO();
$unitExt = new UnitMySqlExtDAO();
//Restaurantrawdestruction
$restaurantRawDestruction = new Restaurantrawdestruction();
$restaurantRawDestructionDAO = new RestaurantrawdestructionMySqlDAO();
$restaurantRawDestructionEX = new RestaurantrawdestructionMySqlExtDAO();
//Programsetting
$Programsetting = new Programsetting();
$ProgramsettingDAO = new ProgramsettingsMySqlDAO();
$ProgramsettingEX = new ProgramsettingsMySqlExtDAO();

$youtubeLink = new YoutubeLink();
$youtubeLinkDAO = new YoutubeLinkMySqlDAO();
$youtubeLinkEX = new YoutubeLinkMySqlExtDAO();
//Usergroup
$Usergroup = new Usergroup();
$UsergroupDAO = new UsergroupMySqlDAO();
$UsergroupEX = new UsergroupMySqlExtDAO();
//
$sizeColorStoreDetail = new Sizecolorstoredetail();
$sizeColorStoreDetailDAO = new SizecolorstoredetailMySqlDAO();
$sizeColorStoreDetailEX = new SizecolorstoredetailMySqlExtDAO();

$today = date("Y-m-d");

$Programsetting = $ProgramsettingDAO->load(1);
$smarty->assign("Programsetting", $Programsetting);
//
$Usergroupdata = $UsergroupDAO->load($_SESSION['usergroupid']);
$smarty->assign("Usergroupdata", $Usergroupdata);
//check and use the condition that suite this action
if (empty($do)) {
    //here the permission check
    include_once("../public/authentication.php");

    //get product categories
//    $catData = getProductCatsForShow();
//    $smarty->assign("catData", $catData);

    $smarty->assign("searchinonestore", $_SESSION['searchinonestore']);
    if ($_SESSION['searchinonestore'] == 0) {
        if ($_SESSION['storeids'] == 0) {
            $stores = $myStoreEx->queryByConditions();
        }else{
            $stores = $myStoreEx->queryByConditions(' and store.storeId in (' . $_SESSION['storeids'] . ')');
        }
        $smarty->assign("stores", $stores);
        $storedef = $myStoreEx->queryByConditionsOne(' and store.storeId = '.$_SESSION['storeid'].' ');
        $smarty->assign("storedef", $storedef);
        $smarty->assign("storeid", $_SESSION['storeid']);
    }else{
        $storedef = $myStoreEx->queryByConditionsOne(' and store.storeId = '.$_SESSION['storeid'].' ');
        $smarty->assign("storedef", $storedef);
        $smarty->assign("storeid", $_SESSION['storeid']);
    }





    // $storesData = getStores();
    // $smarty->assign("storesData", $storesData);

    $smarty->assign("storenegative", $_SESSION['storenegative']);
    //here the smarty templates
    $smarty->display("restaurantRawDestructionView/add.html");


    $smarty->assign("customRestaurantRawDestruction", 1);
}
if ($do == "show") {
    //here the permission check
    include_once("../public/authentication.php");

    $storeId = $_POST['storeId'];
    $from = $_POST['from'];
    $to = $_POST['to'];
    $showopnum = (int) $_POST['showopnum'];
    $smarty->assign("showopnum", $showopnum);


    $youtubes = $youtubeLinkDAO->queryAll();
    $smarty->assign("youtubes", $youtubes);

    //get product categories
//    $catData = getProductCatsForShow();
//    $smarty->assign("catData", $catData);

     $smarty->assign("searchinonestore", $_SESSION['searchinonestore']);
    if ($_SESSION['searchinonestore'] == 0) {
        if ($_SESSION['storeids'] == 0) {
            $stores = $myStoreEx->queryByConditions();
        }else{
            $stores = $myStoreEx->queryByConditions(' and store.storeId in (' . $_SESSION['storeids'] . ')');
        }
        $smarty->assign("stores", $stores);
        $storedef = $myStoreEx->queryByConditionsOne(' and store.storeId = '.$_SESSION['storeid'].' ');
        $smarty->assign("storedef", $storedef);
        $smarty->assign("storeid", $_SESSION['storeid']);
    }else{
        $storedef = $myStoreEx->queryByConditionsOne(' and store.storeId = '.$_SESSION['storeid'].' ');
        $smarty->assign("storedef", $storedef);
        $smarty->assign("storeid", $_SESSION['storeid']);
    }





    // $storesData = getStores();
    // $smarty->assign("storesData", $storesData);

    $smarty->assign("storenegative", $_SESSION['storenegative']);

    ///////
    $arrContainer = getShowData($storeId, $from, $to, $showopnum, $operationnum);

    $smarty->assign("arrContainer", $arrContainer);
    $smarty->display("restaurantRawDestructionView/show.html");

    $smarty->assign("customRestaurantRawDestruction", 1);
} elseif ($do == "add") {
    include_once("../public/authentication.php");

    try {
        $opNum = add();
        $url = "restaurantRawDestruction.php?";
        $smarty->assign('urldirect', $url);
        $note = "تمت العملية بنجاح";
        $smarty->assign('msgnote', $note);
        $smarty->display("notes.html");
        echo "<script type='text/javascript'>window.open('restaurantRawDestruction.php?do=printoperation&num=" . $opNum . "');</script>";
    } catch (Exception $e) {

        echo $e;
        /* $url = "restaurantRawDestruction.php?";
          $smarty->assign('urldirect', $url);
          $note ="حدث خطأ ... يرجى المحاولة مرة أخرى";
          $smarty->assign('msgnote', $note);
          $smarty->display("notes.html"); */
    }
} elseif ($do == "printoperation") {
    $operationnum = (int) $_GET['num'];
    $arrContainer = getShowData(0, '', '', 0, $operationnum);

    $smarty->assign("arrContainer", $arrContainer);
    $smarty->display("restaurantRawDestructionView/printoperation.html");
}
//here the global templates
$smarty->assign("customRestaurantRawDestruction", 1);
if ($do != "printoperation")
    $smarty->display("footer.html");

/* ===============================
  function in this CONTROLLER
  ================================ */

function getProductCatsForShow() {
    global $productExt;
    global $productCatDAO;
    global $smarty;
    $categories;
    $productsData = $productExt->queryAllProducts();

    if (count($productsData) > 0) {
        $i = 0;
        foreach ($productsData as $pro) {
            $parentId = $pro->productCatId;
            $pathArr = fetch_recursive($parentId, $categories);
            $smarty->assign("names" . $i, $pathArr);
            $smarty->assign("parentId" . $i, $parentId);
            $i++;
        }
        $itr = $i - 1;
        $smarty->assign("itr", $itr);
    }
    return $productsData;
}

function fetch_recursive($parentid, $categories) {
    global $productCatExt;
    $catData = $productCatExt->getCategoryAndParentByCatId($parentid);

    if (count($catData) > 0) {
        $categories .= $catData->productCatName . '/';
        $newParentId = $catData->productCatParent;

        if ($newParentId != 0) {
            $newParentName = $catData->parentName;
            $categories .= $newParentName . '/';
            fetch_recursive($newParentId, $categories);
        }
    }
    $categories = substr($categories, 0, strlen($categories) - 1);
    return $categories;
}

function getStores() {
    global $storeDAO;

    $storesData = $storeDAO->queryByConditions(0);
    return $storesData;
}

function getShowData($storeId, $from, $to, $showopnum, $operationNum) {
    global $restaurantRawDestructionEX;
    global $Programsetting;

    $queryString = '';
    if ($storeId > 0) {
        $queryString .= " and storeid = $storeId ";
    }else if ($_SESSION['searchinonestore'] == 0) {
        if ($_SESSION['storeids'] != 0) {
        $queryString .= ' and storeid in (' . $_SESSION['storeids'] . ') ';
        }
    }else{
        $queryString .= ' and storeid = '.$_SESSION['storeid'].' ';
    }




    if ($operationNum > 0) {
        $queryString .= " and operationNum = $operationNum ";
    }

    if (!empty($from)) {
        $queryString .= " and sysdate >= '" . $from . "' ";
    }
    if (!empty($to)) {
        $queryString .= " and sysdate <= '" . $to . "' ";
    }

    if ($queryString != '') {
        if ($showopnum == 1) {
            $queryString .= " and operationNum > 0  group by operationNum order by operationNum desc ";
            $resturantData = $restaurantRawDestructionEX->queryByQueryStringGather($queryString);
        } else {
            $queryString .= " order by operationNum desc ";
            $resturantData = $restaurantRawDestructionEX->queryByQueryString($queryString);
        }
    }

    $i = 1;
    foreach ($resturantData as $restVal) {
        $productData = getProductInStore($restVal->storeid, $restVal->productid, $restVal->sizeid, $restVal->colorid);

        foreach ($productData as $proVal) {
            $buyprice = 0;
            switch ($Programsetting->Inventoryevaluation) {
                case "first":
                    $buyprice = (float) $restVal->productBuyPrice;
                    break;
                case "last":
                    $buyprice = (float) $restVal->lastbuyprice;
                    break;
                case "mean":
                case "generalPrice":
                    $buyprice = (float) $restVal->meanbuyprice;
                    break;
                case "last_discount":
                    $buyprice = (float) $restVal->lastbuyprice_withDiscount;
                    break;
                case "mean_discount":
                    $buyprice = (float) $restVal->meanbuyprice_withDiscount;
                    break;
                case "tax":
                    $buyprice = (float) $restVal->lastbuyprice_withTax;
                    break;
                case "mean_tax":
                    $buyprice = (float) $restVal->meanbuyprice_withTax;
                    break;
            }

            $arrContainer[] = array(
                'itra' => $i,
                'storeName' => $proVal->storeName,
                'productName' => $proVal->productName,
                'distroyQuantity' => $restVal->quantity,
                'date' => $restVal->sysdate,
                'price' => $buyprice,
                'operationNum' => $restVal->operationNum,
                'employeename' => $restVal->employeename,
                'note' => $restVal->note,
            );
            $i++;
        }
    }

    return $arrContainer;
}

function add() {
    global $storeDetail;
    global $storeDetailDAO;
    global $storeDetailExt;
    global $sizeColorStoreDetailDAO;
    global $sizeColorStoreDetailEX;
    global $storeReport;
    global $storeReportDAO;
    global $restaurantrawdestruction;
    global $restaurantRawDestructionDAO;
    global $restaurantRawDestructionEX;
    global $productDAO;
    global $today;

    $itr = $_POST['itr'];
    $operationNum = 0;
    $realestateid = $_POST['realestateid'];
    $realestateunitid = $_POST['realestateunitid'];
    //print_r('itr='.$itr);
    for ($i = 1; $i <= $itr; $i++) {
        $decreaseQty = $_POST['newQty' . $i];
        $productId = $_POST['product' . $i];
        $storedetailid = $_POST['storedetailid' . $i];
        $oldQty = $_POST['oldQty' . $i];
        $note = $_POST['note' . $i];
        $storeid = $_POST['storeId_hidden'];

        $sizeId = 0;
        $colorId = 0;
        if (strpos($productId, "hasSizeColor") !== false) {
            $productIdComplex = explode('-', str_replace("hasSizeColor", "", $productId));
            $productId = $productIdComplex[0];
            $sizeId = $productIdComplex[1];
            $colorId = $productIdComplex[2];
        }

        if (isset($decreaseQty) && $decreaseQty != '' && isset($oldQty) && $oldQty != '') {

            //check if quantity increased or decreased
            $status = "بالنقص";
            $storeDetail = $storeDetailExt->getProductQuantity($productId, $storeid);
            //
            $oldQty = $storeDetail->productquantity;
            $actualQty = $oldQty - $decreaseQty;
            $type = 1;

            //update quantity in storedetail
            $storeDetail->productquantity = $actualQty;
            $storeDetail->userid = $_SESSION['userid'];
            $storeDetail->storeid = $storeid;
            $storeDetail->storedetaildate = $today;
            $storeDetail->storedetailid = $storedetailid;

            /* print_r("<pre>");
              print_r($storeDetail);
              print_r("<pre>"); */
            $storeDetailExt->updateProductquantity($storeDetail);


            //now affect product to in size color stores
            if ($sizeId > 0 && $colorId > 0) {
                $sizeColorStoreDetailId = $sizeColorStoreDetailEX->getIdByProductStoreSizeAndColorEX($productId, $storeid, $sizeId, $colorId);
                if (empty($sizeColorStoreDetailId)) {
                    //
                    $oldQty = 0;
                    //try to copy from existing data in store 1
                    $sizeColorStoreDetailId2 = $sizeColorStoreDetailEX->getIdByProductStoreSizeAndColorEX($storedetailData->productid, 1, $sizeId, $colorId);
                    $sizeColorStoreDetail = $sizeColorStoreDetailDAO->load($sizeColorStoreDetailId2);

                    $sizeColorStoreDetail->storeid = $storedetailData->storeid;
                    $sizeColorStoreDetail->quantity = $decreaseQty * -1;
                    $sizeColorStoreDetail->userid = $_SESSION['userid'];
                    $sizeColorStoreDetail->sysdate = date("Y-m-d H:i:s");

                    $sizeColorStoreDetailId = $sizeColorStoreDetailDAO->insert($sizeColorStoreDetail);
                } else {
                    $sizecolorstoredetail = $sizeColorStoreDetailDAO->load($sizeColorStoreDetailId);
                    //
                    $oldQty = $sizecolorstoredetail->quantity;
                    $sizecolorstoredetail->userid = $_SESSION['userid'];
                    $sizecolorstoredetail->sysdate = date("Y-m-d H:i:s");
                    $sizecolorstoredetail->quantity -= $decreaseQty;
                    $sizeColorStoreDetailDAO->update($sizecolorstoredetail);
                }
            }



            //insert new row into storereport
            $storeReport->processname = "اهلاك خامات" . $status;
            $storeReport->productafter = $actualQty;
            $storeReport->productbefore = $oldQty;
            $storeReport->productid = $productId;
            $storeReport->sizeid = $sizeId;
            $storeReport->colorid = $colorId;
            $storeReport->productquantity = $decreaseQty;
            $storeReport->storeid = $storeid;
            $storeReport->storereportdate = $today;
            $storeReport->storereportmodelid = -1;
            $storeReport->storereporttype = $type;
            $storeReport->tablename = "restaurantRawDestruction.php";
            $storeReport->userid = $_SESSION['userid'];
            //print_r($storeReport);
            $storeReportDAO->insert($storeReport);
            //
            $productData = $productDAO->load($productId);
            if (empty($operationNum)) {
                $maxOperationNum = $restaurantRawDestructionEX->getMaxOperationNum();
                $operationNum = $maxOperationNum + 1;
            }
            $restaurantrawdestruction->storeid = $storeid;
            $restaurantrawdestruction->productid = $productId;
            $restaurantrawdestruction->quantity = $decreaseQty;
            $restaurantrawdestruction->realestateid = $realestateid;
            $restaurantrawdestruction->realestateunitid = $realestateunitid;
            $restaurantrawdestruction->productBuyPrice = $productData->productBuyPrice;
            $restaurantrawdestruction->lastbuyprice = $productData->lastbuyprice;
            $restaurantrawdestruction->meanbuyprice = $productData->meanbuyprice;
            $restaurantrawdestruction->lastbuyprice_withDiscount = $productData->lastbuyprice_withDiscount;
            $restaurantrawdestruction->meanbuyprice_withDiscount = $productData->meanbuyprice_withDiscount;
            $restaurantrawdestruction->lastbuyprice_withTax = $productData->lastbuyprice_withTax;
            $restaurantrawdestruction->meanbuyprice_withTax = $productData->meanbuyprice_withTax;
            $restaurantrawdestruction->conditions = 0;
            $restaurantrawdestruction->sysdate = date('Y-m-d');
            $restaurantrawdestruction->userid = $_SESSION['userid'];
            $restaurantrawdestruction->operationNum = $operationNum;
            $restaurantrawdestruction->sizeid = $sizeId;
            $restaurantrawdestruction->colorid = $colorId;
            $restaurantrawdestruction->note = $note;
            $restaurantRawDestructionDAO->insert($restaurantrawdestruction);

            doInventoryDailyEntry($storeid, $productId, $decreaseQty, $actualQty);
        }
    }

    return $operationNum;
}

function getProductInStore($storeId, $productid, $sizeId, $colorId) {
    global $storeDetailExt;
    global $storeReportExt;
    global $productDAO;
    global $productExt;
    $queryString = " where storedetail.storeId = $storeId and storedetail.productid = $productid ";
    //$queryString = ' where product.productId = 7 ';
    // $productData = $storeDetailExt->queryWithStoreIdExt($storeId);
    $productData = $storeDetailExt->querGroupProducts($queryString);
    if (count($productData) > 0) {
        foreach ($productData as $pro) {

            ///////////To show product category name (the product whole path)
            $parentId = $pro->productCatId;
            //names of product's parents
            $pathArr = fetch_recursive($parentId, $categories);

            //new product name with all path
            $pro->productName = $pro->productName . '/' . $pathArr;

            $sizeColor = $productExt->loadSizeColor($productid, $sizeId, $colorId);
            if (!is_null($sizeColor->sizeName) && !empty($sizeColor->sizeName)) {
                $pro->productName .= '/' . $sizeColor->sizeName;
            }
            if (!is_null($sizeColor->colorName) && !empty($sizeColor->colorName)) {
                $pro->productName .= '/' . $sizeColor->colorName;
            }
        }
    }
    return $productData;
}

function doInventoryDailyEntry($storeId, $productId, $quantity, $newQty) {
    ## 1- get needed data
    $store = R::getRow('select storeName,treeId from store where storeId=' . $storeId);
    $dailyEntryCostprice = R::getCell('select dailyEntryCostprice from programsettings where programsettingsid=1');
    $priceColName = '';
    switch ($dailyEntryCostprice) {
        case "first":
            $priceColName = 'productBuyPrice';
            break;
        case "last":
            $priceColName = 'lastbuyprice';
            break;
        case "mean":
            $priceColName = 'meanbuyprice';
            break;
        case "last_discount":
            $priceColName = 'lastbuyprice_withDiscount';
            break;
        case "mean_discount":
            $priceColName = 'meanbuyprice_withDiscount';
            break;
        case "tax":
            $priceColName = 'lastbuyprice_withTax';
            break;
        case "mean_tax":
            $priceColName = 'meanbuyprice_withTax';
            break;
        case "generalPrice":
            $priceColName = 'meanbuyprice_withTax';
            break;
//        case "realBuyPrice":
//            $priceColName = 'meanbuyprice';
//            break;
        default:
            $priceColName = 'meanbuyprice';
            break;
    }
    $productData = R::getRow('select ' . $priceColName . ' as price,productName,productCatId from product where productId=' . $productId);
    $catName = R::getCell('select productCatName from productcat where productCatId=' . $productData['productCatId']);
    $productCost = $productData['price'] * $quantity;
    $productName = "(" . $productData['productName'] . "/" . $catName . ")";
    $store ['storeName'] = "(" . $store ['storeName'] . ")";



    ## 2- do entry
    $dailyEntry->entryComment = 'تالف مواد تشغيل للمنتج : ' . $productName . ' فى مخزن : ' . $store ['storeName'] . ' بالكمية : ' . $quantity . '';
    //من خامات مهلكة
    $dailyEntryDebtorArray = array();
    $dailyEntryDebtor->accountstreeid = 189;
    $dailyEntryDebtor->value = $productCost;
    //الى المخزن
    $dailyEntryCreditorArray = array();
    $dailyEntryCreditor->accountstreeid = $store['treeId'];
    $dailyEntryCreditor->value = $productCost;

    array_push($dailyEntryCreditorArray, $dailyEntryCreditor);
    array_push($dailyEntryDebtorArray, $dailyEntryDebtor);
    $returnedData = insertEntery($dailyEntry, $dailyEntryDebtorArray, $dailyEntryCreditorArray, 0, $productId, 'productController.php?do=edit&id=' . $productId);

    $did = $returnedData[1];
    return $did;
}

?>