Example #1
0
     */
    $_SESSION['ExistingOrder' . $identifier] = 0;
    unset($_SESSION['PO' . $identifier]);
    /* initialise new class object */
    $_SESSION['PO' . $identifier] = new PurchOrder();
    /*
     * and fill it with essential data
     */
    $_SESSION['PO' . $identifier]->AllowPrintPO = 1;
    /* Of course 'cos the order aint even started !!*/
    $_SESSION['PO' . $identifier]->GLLink = $_SESSION['CompanyRecord']['gllink_stock'];
    /* set the SupplierID we got */
    $_SESSION['PO' . $identifier]->SupplierID = $_GET['SelectedSupplier'];
    $_SESSION['RequireSupplierSelection'] = 0;
    $_POST['Select'] = $_GET['SelectedSupplier'];
    $_SESSION['PO' . $identifier]->DeliveryDate = DateAdd(date($_SESSION['DefaultDateFormat']), 'd', $_GET['LeadTime']);
    $_SESSION['PO' . $identifier]->Initiator = $_SESSION['UserID'];
    $_SESSION['PO' . $identifier]->StatusMessage = '';
    /*
     * the item (its item code) that should be purchased
     */
    $Purch_Item = $_GET['StockID'];
}
if ((isset($_POST['EnterLines']) or isset($_POST['LookupDeliveryAddress']) or isset($_POST['SearchSuppliers'])) and isset($_POST['StkLocation'])) {
    /*User hit the button to enter line items -
     *  ensure session variables updated then meta refresh to PO_Items.php*/
    $_SESSION['PO' . $identifier]->Location = $_POST['StkLocation'];
    $_SESSION['PO' . $identifier]->SupplierContact = $_POST['SupplierContact'];
    $_SESSION['PO' . $identifier]->DelAdd1 = $_POST['DelAdd1'];
    $_SESSION['PO' . $identifier]->DelAdd2 = $_POST['DelAdd2'];
    $_SESSION['PO' . $identifier]->DelAdd3 = $_POST['DelAdd3'];
 $LastPrice = 0;
 while ($myrow = DB_fetch_array($MovtsResult)) {
     if ($LastPrice != $myrow['price'] or $LastDiscount != $myrow['discountpercent']) {
         /* consolidate price history for records with same price/discount */
         if (isset($qty)) {
             $DateRange = ConvertSQLDate($FromDate);
             if ($FromDate != $ToDate) {
                 $DateRange .= ' - ' . ConvertSQLDate($ToDate);
             }
             $PriceHistory[] = array($DateRange, $qty, $LastPrice, $LastDiscount);
             $k++;
             if ($k > 9) {
                 break;
                 /* 10 price records is enough to display */
             }
             if ($myrow['trandate'] < FormatDateForSQL(DateAdd(date($_SESSION['DefaultDateFormat']), 'y', -1))) {
                 break;
                 /* stop displaying pirce history more than a year old once we have at least one  to display */
             }
         }
         $LastPrice = $myrow['price'];
         $LastDiscount = $myrow['discountpercent'];
         $ToDate = $myrow['trandate'];
         $qty = 0;
     }
     $qty += $myrow['qty'];
     $FromDate = $myrow['trandate'];
 }
 if (isset($qty)) {
     $DateRange = ConvertSQLDate($FromDate);
     if ($FromDate != $ToDate) {
	AND DATE_ADD(recurringsalesorders.lastrecurrence, ' . INTERVAL('365/recurringsalesorders.frequency', 'DAY') . ') <= recurringsalesorders.stopdate';
$RecurrOrdersDueResult = DB_query($sql, $db, _('There was a problem retrieving the recurring sales order templates. The database reported:'));
if (DB_num_rows($RecurrOrdersDueResult) == 0) {
    prnMsg(_('There are no recurring order templates that are due to have another recurring order created'), 'warn');
    include 'includes/footer.inc';
    exit;
}
echo '<BR>The number of recurring orders to process is : ' . DB_num_rows($RecurrOrdersDueResult);
while ($RecurrOrderRow = DB_fetch_array($RecurrOrdersDueResult)) {
    $EmailText = '';
    echo '<BR>' . _('Recurring order') . ' ' . $RecurrOrderRow['recurrorderno'] . ' ' . _('for') . ' ' . $RecurrOrderRow['debtorno'] . ' - ' . $RecurrOrderRow['branchcode'] . ' ' . _('is being processed');
    $result = DB_Txn_Begin($db);
    /*the last recurrence was the date of the last time the order recurred
    	the frequency is the number of times per annum that the order should recurr
    	so 365 / frequency gives the number of days between recurrences */
    $DelDate = FormatDateforSQL(DateAdd(ConvertSQLDate($RecurrOrderRow['lastrecurrence']), 'd', 365 / $RecurrOrderRow['frequency']));
    echo '<BR>Date calculated for the next recurrence was: ' . $DelDate;
    $HeaderSQL = "INSERT INTO salesorders (\n\t\t\t\tdebtorno,\n\t\t\t\tbranchcode,\n\t\t\t\tcustomerref,\n\t\t\t\tcomments,\n\t\t\t\torddate,\n\t\t\t\tordertype,\n\t\t\t\tshipvia,\n\t\t\t\tdeliverto,\n\t\t\t\tdeladd1,\n\t\t\t\tdeladd2,\n\t\t\t\tdeladd3,\n\t\t\t\tdeladd4,\n\t\t\t\tdeladd5,\n\t\t\t\tdeladd6,\n\t\t\t\tcontactphone,\n\t\t\t\tcontactemail,\n\t\t\t\tfreightcost,\n\t\t\t\tfromstkloc,\n\t\t\t\tdeliverydate )\n\t\t\tVALUES (\n\t\t\t\t'" . $RecurrOrderRow['debtorno'] . "',\n\t\t\t\t'" . $RecurrOrderRow['branchcode'] . "',\n\t\t\t\t'" . $RecurrOrderRow['customerref'] . "',\n\t\t\t\t'" . $RecurrOrderRow['comments'] . "',\n\t\t\t\t'" . $DelDate . "',\n\t\t\t\t'" . $RecurrOrderRow['ordertype'] . "',\n\t\t\t\t" . $RecurrOrderRow['shipvia'] . ",\n\t\t\t\t'" . $RecurrOrderRow['deliverto'] . "',\n\t\t\t\t'" . $RecurrOrderRow['deladd1'] . "',\n\t\t\t\t'" . $RecurrOrderRow['deladd2'] . "',\n\t\t\t\t'" . $RecurrOrderRow['deladd3'] . "',\n\t\t\t\t'" . $RecurrOrderRow['deladd4'] . "',\n\t\t\t\t'" . $RecurrOrderRow['deladd5'] . "',\n\t\t\t\t'" . $RecurrOrderRow['deladd6'] . "',\n\t\t\t\t'" . $RecurrOrderRow['contactphone'] . "',\n\t\t\t\t'" . $RecurrOrderRow['contactemail'] . "',\n\t\t\t\t" . $RecurrOrderRow['freightcost'] . ",\n\t\t\t\t'" . $RecurrOrderRow['fromstkloc'] . "',\n\t\t\t\t'" . $DelDate . "')";
    $ErrMsg = _('The order cannot be added because');
    $InsertQryResult = DB_query($HeaderSQL, $db, $ErrMsg, true);
    $OrderNo = GetNextTransNo(30, $db);
    $EmailText = _('A new order has been created from a recurring order template for customer') . ' ' . $RecurrOrderRow['debtorno'] . ' ' . $RecurrOrderRow['branchcode'] . "\n" . _('The order number is:') . ' ' . $OrderNo;
    /*need to look up RecurringOrder from the template and populate the line RecurringOrder array with the sales order details records */
    $LineItemsSQL = "SELECT recurrsalesorderdetails.stkcode,\n\t\t\t\trecurrsalesorderdetails.unitprice,\n\t\t\t\trecurrsalesorderdetails.quantity,\n\t\t\t\trecurrsalesorderdetails.discountpercent,\n\t\t\t\trecurrsalesorderdetails.narrative,\n\t\t\t\tstockmaster.taxcatid\n\t\t\tFROM recurrsalesorderdetails INNER JOIN stockmaster\n\t\t\t\tON recurrsalesorderdetails.stkcode = stockmaster.stockid\n\t\t\tWHERE recurrsalesorderdetails.recurrorderno =" . $RecurrOrderRow['recurrorderno'];
    $ErrMsg = _('The line items of the recurring order cannot be retrieved because');
    $LineItemsResult = db_query($LineItemsSQL, $db, $ErrMsg);
    $LineCounter = 0;
    if (db_num_rows($LineItemsResult) > 0) {
        $OrderTotal = 0;
        //intialise
        $OrderLineTotal = 0;
        #end if SearchResults to show
    } elseif (isset($_POST['QuickEntry'])) {
        /* show the quick entry form variable */
        /*FORM VARIABLES TO POST TO THE ORDER  WITH PART CODE AND QUANTITY */
        echo '<div class="page_help_text"><b>' . _('Use this screen for the ') . _('Quick Entry') . _(' of products to be ordered') . '</b></div><br />
		 			<table class="selection">
					<tr>';
        /*do not display colum unless customer requires po line number by sales order line*/
        if ($_SESSION['Items' . $identifier]->DefaultPOLine == 1) {
            echo '<th>' . _('PO Line') . '</th>';
        }
        echo '<th>' . _('Part Code') . '</th>
				  <th>' . _('Quantity') . '</th>
				  <th>' . _('Due Date') . '</th>
				  </tr>';
        $DefaultDeliveryDate = DateAdd(Date($_SESSION['DefaultDateFormat']), 'd', $_SESSION['Items' . $identifier]->DeliveryDays);
        for ($i = 1; $i <= $_SESSION['QuickEntries']; $i++) {
            echo '<tr class="OddTableRow">';
            /* Do not display colum unless customer requires po line number by sales order line*/
            if ($_SESSION['Items' . $identifier]->DefaultPOLine > 0) {
                echo '<td><input type="text" name="poline_' . $i . '" size="21" maxlength="20" /></td>';
            }
            echo '<td><input type="text" name="part_' . $i . '" size="21" maxlength="20" /></td>
						<td><input type="text" name="qty_' . $i . '" size="6" maxlength="6" /></td>
						<td><input type="text" class="date" name="itemdue_' . $i . '" size="25" maxlength="25" alt="' . $_SESSION['DefaultDateFormat'] . '" value="' . $DefaultDeliveryDate . '" /></td></tr>';
        }
        echo '<script  type="text/javascript">if (document.SelectParts) {defaultControl(document.SelectParts.part_1);}</script>';
        echo '</table><br /><div class="centre"><button type="submit" name="QuickEntry">' . _('Quick Entry') . '</button>
					 <button type="submit" name="PartSearch">' . _('Search Parts') . '</button></div>';
    } elseif (isset($_POST['SelectAsset'])) {
        echo '<div class="page_help_text"><b>' . _('Use this screen to select an asset to dispose of to this customer') . '</b></div><br />
Example #5
0
    echo '<tr><td colspan="2"><div class="centre"><button type="submit" name="submit">' . _('Select') . '</button></div></td></tr>';
    echo '</table></form>';
}
if (isset($_POST['NewItem']) and !isset($_POST['Refresh'])) {
    foreach ($_POST as $key => $value) {
        if (mb_substr($key, 0, 7) == 'StockID') {
            $Index = mb_substr($key, 7, mb_strlen($key) - 7);
            $StockID = $value;
            $Quantity = filter_number_input($_POST['Qty' . $Index]);
            $Price = filter_currency_input($_POST['Price' . $Index]);
            $UOM = $_POST['uom' . $Index];
            if (isset($UOM) and $Quantity > 0) {
                $sql = "SELECT description, decimalplaces FROM stockmaster WHERE stockid='" . $StockID . "'";
                $result = DB_query($sql, $db);
                $myrow = DB_fetch_array($result);
                $_SESSION['offer' . $identifier]->add_to_offer($_SESSION['offer' . $identifier]->LinesOnOffer, $StockID, $Quantity, $myrow['description'], $Price, $UOM, $myrow['decimalplaces'], DateAdd(date($_SESSION['DefaultDateFormat']), 'm', 3));
                unset($UOM);
            }
        }
    }
}
if (isset($_POST['Refresh']) and !isset($_POST['NewItem'])) {
    foreach ($_POST as $key => $value) {
        if (mb_substr($key, 0, 7) == 'StockID') {
            $Index = mb_substr($key, 7, mb_strlen($key) - 7);
            $StockID = $value;
            $Quantity = filter_number_input($_POST['Qty' . $Index]);
            $Price = filter_currency_input($_POST['Price' . $Index]);
            $ExpiryDate = $_POST['expirydate' . $Index];
        }
        if (isset($ExpiryDate)) {
    }
    //View number of days
    echo '<tr>
			<td>' . _('Number Of Days') . ' </td>
			<td>:</td>
			<td><input class="integer" tabindex="3" type="text" required="required" title="' . _('Enter the number of days to examine the sales for') . '" name="NumberOfDays" size="8" maxlength="8" value="30" /></td>
		 </tr>
	</table>
	<br />
	<div class="centre">
		<input tabindex="5" type="submit" name="Search" value="' . _('Search') . '" />
	</div>
	</form>';
} else {
    // everything below here to view NumberOfNoSalesItems on selected location
    $FromDate = FormatDateForSQL(DateAdd(Date($_SESSION['DefaultDateFormat']), 'd', -filter_number_format($_POST['NumberOfDays'])));
    if ($_POST['StockCat'] == 'All') {
        $WhereStockCat = "";
    } else {
        $WhereStockCat = " AND stockmaster.categoryid = '" . $_POST['StockCat'] . "'";
    }
    if ($_POST['Location'][0] == 'All') {
        $SQL = "SELECT \tstockmaster.stockid,\n\t\t\t\t\tstockmaster.description,\n\t\t\t\t\tstockmaster.units\n\t\t\t\tFROM \tstockmaster,locstock\n\t\t\t\tINNER JOIN locationusers ON locationusers.loccode=locstock.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1\n\t\t\t\tWHERE \tstockmaster.stockid = locstock.stockid " . $WhereStockCat . "\n\t\t\t\t\tAND (locstock.quantity > 0)\n\t\t\t\t\tAND NOT EXISTS (\n\t\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\t\tFROM \tsalesorderdetails, salesorders\n\t\t\t\t\t\t\tINNER JOIN locationusers ON locationusers.loccode=salesorders.fromstkloc AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1\n\t\t\t\t\t\t\tWHERE \tstockmaster.stockid = salesorderdetails.stkcode\n\t\t\t\t\t\t\t\t\tAND (salesorderdetails.orderno = salesorders.orderno)\n\t\t\t\t\t\t\t\t\tAND salesorderdetails.actualdispatchdate > '" . $FromDate . "')\n\t\t\t\t\tAND NOT EXISTS (\n\t\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\t\tFROM \tstockmoves\n\t\t\t\t\t\t\tINNER JOIN locationusers ON locationusers.loccode=stockmoves.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1\n\t\t\t\t\t\t\tWHERE \tstockmoves.stockid = stockmaster.stockid\n\t\t\t\t\t\t\t\t\tAND stockmoves.trandate >= '" . $FromDate . "')\n\t\t\t\t\tAND EXISTS (\n\t\t\t\t\t\t\tSELECT *\n\t\t\t\t\t\t\tFROM \tstockmoves\n\t\t\t\t\t\t\tINNER JOIN locationusers ON locationusers.loccode=stockmoves.loccode AND locationusers.userid='" . $_SESSION['UserID'] . "' AND locationusers.canview=1\n\t\t\t\t\t\t\tWHERE \tstockmoves.stockid = stockmaster.stockid\n\t\t\t\t\t\t\t\t\tAND stockmoves.trandate < '" . $FromDate . "'\n\t\t\t\t\t\t\t\t\tAND stockmoves.qty >0)\n\t\t\t\tGROUP BY stockmaster.stockid\n\t\t\t\tORDER BY stockmaster.stockid";
    } else {
        $WhereLocation = '';
        if (sizeof($_POST['Location']) == 1) {
            $WhereLocation = " AND locstock.loccode ='" . $_POST['Location'][0] . "' ";
        } else {
            $WhereLocation = " AND locstock.loccode IN(";
            $commactr = 0;
            foreach ($_POST['Location'] as $key => $value) {
            $_POST['RoundingFactor'] = filter_number_format($_POST['RoundingFactor']);
            if ($_POST['CostType'] != 'OtherPriceList') {
                $RoundedPrice = round(($Cost * (1 + $IncrementPercentage) * $CurrencyRate + $_POST['RoundingFactor'] / 2) / $_POST['RoundingFactor']) * $_POST['RoundingFactor'];
                if ($RoundedPrice <= 0) {
                    $RoundedPrice = $_POST['RoundingFactor'];
                }
            } else {
                $RoundedPrice = round(($Cost * (1 + $IncrementPercentage) + $_POST['RoundingFactor'] / 2) / $_POST['RoundingFactor']) * $_POST['RoundingFactor'];
                if ($RoundedPrice <= 0) {
                    $RoundedPrice = $_POST['RoundingFactor'];
                }
            }
            if ($Cost > 0) {
                $CurrentPriceResult = DB_query("SELECT price,\n\t\t\t\t\t\t\t\t\t\t\t \t\t   startdate,\n\t\t\t\t\t\t\t\t\t\t\t\t\t   enddate\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM prices\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE typeabbrev= '" . $_POST['PriceList'] . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND debtorno =''\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND currabrev='" . $_POST['CurrCode'] . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND startdate <='" . Date('Y-m-d') . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND (enddate>='" . Date('Y-m-d') . "' OR enddate='0000-00-00')\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND stockid='" . $myrow['stockid'] . "'");
                if (DB_num_rows($CurrentPriceResult) == 1) {
                    $DayPriorToNewPrice = DateAdd($_POST['PriceStartDate'], 'd', -1);
                    $CurrentPriceRow = DB_fetch_array($CurrentPriceResult);
                    $UpdateSQL = "UPDATE prices SET enddate='" . FormatDateForSQL($DayPriorToNewPrice) . "'\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE typeabbrev='" . $_POST['PriceList'] . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND currabrev='" . $_POST['CurrCode'] . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND debtorno=''\n\t\t\t\t\t\t\t\t\t\t\t\tAND startdate ='" . $CurrentPriceRow['startdate'] . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND enddate ='" . $CurrentPriceRow['enddate'] . "'\n\t\t\t\t\t\t\t\t\t\t\t\tAND stockid='" . $myrow['stockid'] . "'";
                    $ErrMsg = _('Error updating prices for') . ' ' . $myrow['stockid'] . ' ' . _('because');
                    $result = DB_query($UpdateSQL, $ErrMsg);
                }
                $sql = "INSERT INTO prices (stockid,\n\t\t\t\t\t\t\t\t\t\t\t\ttypeabbrev,\n\t\t\t\t\t\t\t\t\t\t\t\tcurrabrev,\n\t\t\t\t\t\t\t\t\t\t\t\tstartdate,\n\t\t\t\t\t\t\t\t\t\t\t\tenddate,\n\t\t\t\t\t\t\t\t\t\t\t\tprice)\n\t\t\t\t\t\t\t\tVALUES ('" . $myrow['stockid'] . "',\n\t\t\t\t\t\t\t\t\t\t'" . $_POST['PriceList'] . "',\n\t\t\t\t\t\t\t\t\t\t'" . $_POST['CurrCode'] . "',\n\t\t\t\t\t\t\t\t\t\t'" . FormatDateForSQL($_POST['PriceStartDate']) . "',\n\t\t\t\t\t\t\t\t\t\t'" . $SQLEndDate . "',\n\t\t\t\t\t\t\t\t \t\t'" . filter_number_format($RoundedPrice) . "')";
                $ErrMsg = _('Error inserting new price for') . ' ' . $myrow['stockid'] . ' ' . _('because');
                $result = DB_query($sql, $ErrMsg);
                prnMsg(_('Inserting new price for') . ' ' . $myrow['stockid'] . ' ' . _('to') . ' ' . $RoundedPrice, 'info');
            }
            // end if cost > 0
        }
        //end while loop around items in the category
    }
}
Example #8
0
 $pdf->addTextWrap(310, $YPos, 45, $FontSize, locale_number_format($weeklyavail[14], 0), 'right');
 $pdf->addTextWrap(355, $YPos, 45, $FontSize, locale_number_format($weeklyavail[15], 0), 'right');
 $pdf->addTextWrap(400, $YPos, 45, $FontSize, locale_number_format($weeklyavail[16], 0), 'right');
 $pdf->addTextWrap(445, $YPos, 45, $FontSize, locale_number_format($weeklyavail[17], 0), 'right');
 $pdf->addTextWrap(490, $YPos, 45, $FontSize, locale_number_format($weeklyavail[18], 0), 'right');
 $YPos -= 2 * $line_height;
 // Third Group of Weeks
 $pdf->addTextWrap($Left_Margin + 40, $YPos, 45, $FontSize, DateAdd($today, 'w', 19), 'right');
 $pdf->addTextWrap(130, $YPos, 45, $FontSize, DateAdd($today, 'w', 20), 'right');
 $pdf->addTextWrap(175, $YPos, 45, $FontSize, DateAdd($today, 'w', 21), 'right');
 $pdf->addTextWrap(220, $YPos, 45, $FontSize, DateAdd($today, 'w', 22), 'right');
 $pdf->addTextWrap(265, $YPos, 45, $FontSize, DateAdd($today, 'w', 23), 'right');
 $pdf->addTextWrap(310, $YPos, 45, $FontSize, DateAdd($today, 'w', 24), 'right');
 $pdf->addTextWrap(355, $YPos, 45, $FontSize, DateAdd($today, 'w', 25), 'right');
 $pdf->addTextWrap(400, $YPos, 45, $FontSize, DateAdd($today, 'w', 26), 'right');
 $pdf->addTextWrap(445, $YPos, 45, $FontSize, DateAdd($today, 'w', 27), 'right');
 $pdf->addTextWrap(490, $YPos, 45, $FontSize, "Future", 'right');
 $YPos -= $line_height;
 $pdf->addTextWrap($Left_Margin, $YPos, 40, $FontSize, _('Gross Reqts'));
 $pdf->addTextWrap($Left_Margin + 40, $YPos, 45, $FontSize, locale_number_format($WeeklyReq[19], 0), 'right');
 $pdf->addTextWrap(130, $YPos, 45, $FontSize, locale_number_format($WeeklyReq[20], 0), 'right');
 $pdf->addTextWrap(175, $YPos, 45, $FontSize, locale_number_format($WeeklyReq[21], 0), 'right');
 $pdf->addTextWrap(220, $YPos, 45, $FontSize, locale_number_format($WeeklyReq[22], 0), 'right');
 $pdf->addTextWrap(265, $YPos, 45, $FontSize, locale_number_format($WeeklyReq[23], 0), 'right');
 $pdf->addTextWrap(310, $YPos, 45, $FontSize, locale_number_format($WeeklyReq[24], 0), 'right');
 $pdf->addTextWrap(355, $YPos, 45, $FontSize, locale_number_format($WeeklyReq[25], 0), 'right');
 $pdf->addTextWrap(400, $YPos, 45, $FontSize, locale_number_format($WeeklyReq[26], 0), 'right');
 $pdf->addTextWrap(445, $YPos, 45, $FontSize, locale_number_format($WeeklyReq[27], 0), 'right');
 $pdf->addTextWrap(490, $YPos, 45, $FontSize, locale_number_format($FutureReq, 0), 'right');
 $YPos -= $line_height;
 $pdf->addTextWrap($Left_Margin, $YPos, 40, $FontSize, _('Open Order'));
Example #9
0
 // Chicken pox date
 $cpox = DateAdd("m", 12, $dobdate);
 // Rubella date
 $rubella = DateAdd("m", 144, $dobdate);
 // Hepatitis booster dates
 $hepboost1 = DateAdd("m", 12, $dobdate);
 $hepboost2 = DateAdd("m", 120, $dobdate);
 // OPV booster dates
 $opvboost1 = DateAdd("m", 18, $dobdate);
 $opvboost2 = DateAdd("m", 54, $dobdate);
 // Typhoid booster dates
 //$typhboost=DateAdd("m", 36, $typh);
 $typhboost = date("l, dS of F, Y", $typh);
 $typhboost = "Every three years after {$typhboost}";
 // DT booster date
 $dtboost = DateAdd("m", 96, $dobdate);
 // Format the dates in a presentable form
 if ($today > $bcgdate) {
     $bcgdate = date("l, dS of F, Y", $bcgdate);
     $bcgdate = "<font color=#FF0000>within {$bcgdate}</font>";
 } else {
     $bcgdate = "within " . date("l, dS of F, Y", $bcgdate);
 }
 if ($today > $opv1) {
     $opv1 = date("l, dS of F, Y", $opv1);
     $opv1 = "<font color=#FF0000>{$opv1}</font>";
 } else {
     $opv1 = date("l, dS of F, Y", $opv1);
 }
 if ($today > $opv2) {
     $opv2 = date("l, dS of F, Y", $opv2);
Example #10
0
            echo '<option value="' . $myrow['code'] . '">' . $myrow['description'] . '</option>';
        }
    }
    //end while loop
    DB_free_result($result);
    echo '</select></td>
		</tr>
		<tr>
			<td>' . _('Contract Description') . ':</td>
			<td><textarea name="ContractDescription" style="width:100%" required="required" title="' . _('A description of the contract is required') . '" minlength="5" rows="5" cols="40">' . $_SESSION['Contract' . $identifier]->ContractDescription . '</textarea></td>
		</tr><tr>
			<td>' . _('Drawing File') . ' .jpg' . ' ' . _('format only') . ':</td>
			<td><input type="file" id="Drawing" name="Drawing" /></td>
		</tr>';
    if (!isset($_SESSION['Contract' . $identifier]->RequiredDate)) {
        $_SESSION['Contract' . $identifier]->RequiredDate = DateAdd(date($_SESSION['DefaultDateFormat']), 'm', 1);
    }
    echo '<tr>
			<td>' . _('Required Date') . ':</td>
			<td><input type="text" required="required" class="date" alt="' . $_SESSION['DefaultDateFormat'] . '" name="RequiredDate" size="11" value="' . $_SESSION['Contract' . $identifier]->RequiredDate . '" /></td>
		</tr>';
    echo '<tr>
			<td>' . _('Customer Reference') . ':</td>
			<td><input type="text" name="CustomerRef" required="required" title="' . _('Enter the reference that the customer uses for this contract') . '" size="21" maxlength="20" value="' . $_SESSION['Contract' . $identifier]->CustomerRef . '" /></td>
		</tr>';
    if (!isset($_SESSION['Contract' . $identifier]->Margin)) {
        $_SESSION['Contract' . $identifier]->Margin = 50;
    }
    echo '<tr>
			<td>' . _('Gross Profit') . ' %:</td>
			<td><input class="number" type="text" name="Margin"  required="required" size="6" maxlength="6" value="' . locale_number_format($_SESSION['Contract' . $identifier]->Margin, 2) . '" /></td>
Example #11
0
     } else {
         $sql = "SELECT stockmaster.description,\n\t\t\t\t\t\t\t\tstockmaster.stockid,\n\t\t\t\t\t\t\t\tstockmaster.units,\n\t\t\t\t\t\t\t\tstockmaster.decimalplaces,\n\t\t\t\t\t\t\t\tstockmaster.kgs,\n\t\t\t\t\t\t\t\tstockmaster.netweight,\n\t\t\t\t\t\t\t\tstockcategory.stockact,\n\t\t\t\t\t\t\t\tchartmaster.accountname\n\t\t\t\t\t\t\tFROM stockcategory,\n\t\t\t\t\t\t\t\tchartmaster,\n\t\t\t\t\t\t\t\tstockmaster\n\t\t\t\t\t\t\tWHERE chartmaster.accountcode = stockcategory.stockact\n\t\t\t\t\t\t\t\tAND stockcategory.categoryid = stockmaster.categoryid\n\t\t\t\t\t\t\t\tAND stockmaster.stockid = '" . $ItemCode . "'";
     }
     $ErrMsg = _('The supplier pricing details for') . ' ' . $ItemCode . ' ' . _('could not be retrieved because');
     $DbgMsg = _('The SQL used to retrieve the pricing details but failed was');
     $result1 = DB_query($sql, $db, $ErrMsg, $DbgMsg);
     if ($myrow = DB_fetch_array($result1)) {
         if (isset($myrow['price']) and is_numeric($myrow['price'])) {
             if ($Quantity < $myrow['minorderqty']) {
                 prnMsg(_('The quantity ordered is less than the minimum order quantity for this supplier.') . '<br />' . _('Are you sure you wish to continue?'), 'warn');
             } else {
                 if ($Quantity % $myrow['minorderqty']) {
                     prnMsg(_('The quantity ordered should be a multiple of the minimum order quantity for this supplier.') . '<br />' . _('Are you sure you wish to continue?'), 'warn');
                 }
             }
             $_SESSION['PO' . $identifier]->add_to_order($_SESSION['PO' . $identifier]->LinesOnOrder + 1, $ItemCode, 0, 0, $Quantity, $myrow['description'], $myrow['price'], $myrow['unitname'], $myrow['stockact'], DateAdd(date($_SESSION['DefaultDateFormat']), 'd', $myrow['leadtime']), 0, 0, 0, 0, 0, $myrow['accountname'], $myrow['decimalplaces'], $ItemCode, $myrow['unitname'], $myrow['conversionfactor'], $myrow['leadtime'], $myrow['suppliers_partno'], $Quantity * $myrow['price'], '', 0, $myrow['netweight'], $myrow['kgs'], '', $Quantity, $Quantity * $myrow['price']);
         } else {
             /*There was no supplier purchasing data for the item selected so enter a purchase order line with zero price */
             $_SESSION['PO' . $identifier]->add_to_order($_SESSION['PO' . $identifier]->LinesOnOrder + 1, $ItemCode, 0, 0, $Quantity, $myrow['description'], 0, $myrow['units'], $myrow['stockact'], $_SESSION['PO' . $identifier]->DeliveryDate, 0, 0, 0, 0, 0, $myrow['accountname'], $myrow['decimalplaces'], $ItemCode, $myrow['units'], 1, 1, '', 0, 0, '', 0, 0, 0, 0, 0, 0);
         }
         /*Make sure the line is also available for editing by default without additional clicks */
         //					$_GET['Edit'] = $_SESSION['PO'.$identifier]->LinesOnOrder; /* this is a bit confusing but it was incremented by the add_to_order function */
     } else {
         prnMsg(_('The item code') . ' ' . $ItemCode . ' ' . _('does not exist in the database and therefore cannot be added to the order'), 'error');
         if ($debug == 1) {
             echo '<br />' . $sql;
         }
         include 'includes/footer.inc';
         exit;
     }
 }
Example #12
0
     $PeriodAllocated--;
     //decrement the period
     if ($PeriodNo - $PeriodAllocated > 6) {
         /*if more than 6 months ago when sales were made then forget it */
         break;
     }
     //$PeriodNo - $PeriodAllocated > 6
 }
 //$QuantityVarianceAllocated > 0
 /*end loop around different periods to see which sales analysis records to update */
 /*now we need to work back through the sales stockmoves up to the quantity on this purchase invoice to update costs
  * Only go back up to 6 months looking for stockmoves and
  * Only in the stock location where the purchase order was received
  * into - if the stock was transferred to another location then
  * we cannot adjust for this */
 $result = DB_query("SELECT stkmoveno,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttype,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tqty,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tstandardcost\n\t\t\t\t\t\t\t\t\t\t\t\t\tFROM stockmoves\n\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE loccode='" . $LocCode . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND qty < 0\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND stockid='" . $EnteredGRN->ItemCode . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND trandate>='" . FormatDateForSQL(DateAdd($_SESSION['SuppTrans']->TranDate, 'm', -6)) . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\tORDER BY stkmoveno DESC", $db);
 $ErrMsg = _('CRITICAL ERROR') . '! ' . _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' . _('The stock movements for invoices cannot be updated for the cost variances on this purchase invoice');
 $QuantityVarianceAllocated = $EnteredGRN->This_QuantityInv;
 while ($StkMoveRow = DB_fetch_array($result) and $QuantityVarianceAllocated > 0) {
     if ($StkMoveRow['qty'] + $QuantityVarianceAllocated > 0) {
         if ($StkMoveRow['type'] == 10) {
             //its a sales invoice
             $result = DB_query("UPDATE stockmoves\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSET standardcost = '" . $ActualCost . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE stkmoveno = '" . $StkMoveRow['stkmoveno'] . "'", $db, $ErrMsg, $DbgMsg, True);
         }
         //$StkMoveRow['type'] == 10
     } else {
         //Only $QuantityVarianceAllocated left to allocate so need need to apportion cost using weighted average
         if ($StkMoveRow['type'] == 10) {
             //its a sales invoice
             $WACost = ((-$StkMoveRow['qty'] - $QuantityVarianceAllocated) * $StkMoveRow['standardcost'] + $QuantityVarianceAllocated * $ActualCost) / -$StkMoveRow['qty'];
             $UpdStkMovesResult = DB_query("UPDATE stockmoves\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSET standardcost = '" . $WACost . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE stkmoveno = '" . $StkMoveRow['stkmoveno'] . "'", $db, $ErrMsg, $DbgMsg, True);
Example #13
0
            if ($_POST['FromPeriod'] == $myrow['periodno']) {
                echo '<option selected="selected" value="' . $myrow['periodno'] . '">' . MonthAndYearFromSQLDate($myrow['lastdate_in_period']) . '</option>';
            } else {
                echo '<option value="' . $myrow['periodno'] . '">' . MonthAndYearFromSQLDate($myrow['lastdate_in_period']) . '</option>';
            }
        } else {
            if ($myrow['lastdate_in_period'] == $DefaultFromDate) {
                echo '<option selected="selected" value="' . $myrow['periodno'] . '">' . MonthAndYearFromSQLDate($myrow['lastdate_in_period']) . '</option>';
            } else {
                echo '<option value="' . $myrow['periodno'] . '">' . MonthAndYearFromSQLDate($myrow['lastdate_in_period']) . '</option>';
            }
        }
    }
    echo '</select></td></tr>';
    if (!isset($_POST['ToPeriod']) or $_POST['ToPeriod'] == '') {
        $DefaultToPeriod = GetPeriod(DateAdd(ConvertSQLDate($DefaultFromDate), 'm', 11), $db);
    } else {
        $DefaultToPeriod = $_POST['ToPeriod'];
    }
    echo '<tr>
			<td>' . _('Select Period To:') . '</td>
			<td><select minlength="0" name="ToPeriod">';
    $RetResult = DB_data_seek($Periods, 0);
    while ($myrow = DB_fetch_array($Periods, $db)) {
        if ($myrow['periodno'] == $DefaultToPeriod) {
            echo '<option selected="selected" value="' . $myrow['periodno'] . '">' . MonthAndYearFromSQLDate($myrow['lastdate_in_period']) . '</option>';
        } else {
            echo '<option value ="' . $myrow['periodno'] . '">' . MonthAndYearFromSQLDate($myrow['lastdate_in_period']) . '</option>';
        }
    }
    echo '</select></td></tr>';
 public function initPopup($item, $data)
 {
     if (!empty($data['editType'])) {
         $this->_edit_type = $data['editType'];
         $this->_popup_controller->assign('item', 'edit_type', $data['editType']);
     }
     // assign template vars
     $this->assignTemplateVars();
     $current_context = $this->_environment->getCurrentContextItem();
     if ($item !== null) {
         // edit mode
         // TODO: check rights
         // files
         $attachment_infos = array();
         $converter = $this->_environment->getTextConverter();
         $file_list = $item->getFileList();
         $file = $file_list->getFirst();
         while ($file) {
             #$info['file_name']	= $converter->text_as_html_short($file->getDisplayName());
             $info['file_name'] = $converter->filenameFormatting($file->getDisplayName());
             $info['file_icon'] = $file->getFileIcon();
             $info['file_id'] = $file->getFileID();
             $attachment_infos[] = $info;
             $file = $file_list->getNext();
         }
         $this->_popup_controller->assign('item', 'files', $attachment_infos);
         $this->_popup_controller->assign('item', 'title', $item->getTitle());
         // old formating
         $c_old_text_formating_array = $this->_environment->getConfiguration('c_old_text_formating_array');
         if (!empty($c_old_text_formating_array) and is_array($c_old_text_formating_array) and in_array($this->_environment->getCurrentContextID(), $c_old_text_formating_array)) {
             $this->_with_old_text_formating = true;
         }
         if ($this->_with_old_text_formating) {
             $desc_string = $item->getDescription();
             $desc_string = preg_replace('/(?:[ \\t]*(?:\\n|\\r\\n?)){2,}/', "\n", $desc_string);
             $desc_string = nl2br($desc_string);
             $desc_string = str_replace('<br /><br />', '<br />', $desc_string);
             $this->_popup_controller->assign('item', 'description', $desc_string);
         } else {
             $this->_popup_controller->assign('item', 'description', $item->getDescription());
         }
         $this->_popup_controller->assign('item', 'public', $item->isPublic());
         if ($item->getSeconddateTime() != '') {
             $this->_popup_controller->assign('item', 'dayEnd', mb_substr($item->getSeconddateTime(), 0, 10));
             $this->_popup_controller->assign('item', 'timeEnd', getTimeInLang($item->getSeconddateTime()));
         } else {
             $time = $current_context->getTimeSpread();
             $this->_popup_controller->assign('item', 'dayEnd', DateAdd($time, date("Y-m-d"), "Y-m-d"));
             $this->_popup_controller->assign('item', 'timeEnd', date("H:m"));
         }
         $activating = false;
         if ($current_context->withActivatingContent()) {
             $activating = true;
             $this->_popup_controller->assign('item', 'private_editing', $item->isPrivateEditing());
             if ($item->isNotActivated()) {
                 $this->_popup_controller->assign('item', 'is_not_activated', true);
                 $activating_date = $item->getActivatingDate();
                 if (!stristr($activating_date, '9999')) {
                     $this->_popup_controller->assign('item', 'activating_date', mb_substr($activating_date, 0, 10));
                     $this->_popup_controller->assign('item', 'activating_time', mb_substr($activating_date, -8));
                 }
             }
         }
         $this->_popup_controller->assign('popup', 'activating', $activating);
     } else {
         $time = $current_context->getTimeSpread();
         $this->_popup_controller->assign('item', 'dayEnd', DateAdd($time, date("Y-m-d"), "Y-m-d"));
         $this->_popup_controller->assign('item', 'timeEnd', date("H:m"));
         if ($current_context->isCommunityRoom()) {
             $this->_popup_controller->assign('item', 'public', '1');
         } else {
             $this->_popup_controller->assign('item', 'public', '0');
         }
     }
 }
Example #15
0
function LevelNetting(&$db, $part, $eoq, $PanSize, $ShrinkFactor, $LeadTime)
{
    // Create an array of mrprequirements and an array of mrpsupplies, then read through
    // them seeing if all requirements are covered by supplies. Create a planned order
    // for any unmet requirements. Change dates if necessary for the supplies.
    //echo '<br />Part is ' . "$part" . '<br />';
    // Get decimal places from stockmaster for rounding of shrinkage factor
    $sql = "SELECT decimalplaces FROM stockmaster WHERE stockid = '" . $part . "'";
    $result = DB_query($sql, $db);
    $myrow = DB_fetch_row($result);
    $DecimalPlaces = $myrow[0];
    // Load mrprequirements into $Requirements array
    $sql = "SELECT * FROM mrprequirements WHERE part = '" . $part . "' ORDER BY daterequired";
    $result = DB_query($sql, $db);
    $Requirements = array();
    $i = 0;
    while ($myrow = DB_fetch_array($result)) {
        array_push($Requirements, $myrow);
        $i++;
    }
    //end of while loop
    // Load mrpsupplies into $Supplies array
    $sql = "SELECT * FROM mrpsupplies WHERE part = '" . $part . "' ORDER BY duedate";
    $result = DB_query($sql, $db);
    $Supplies = array();
    $i = 0;
    while ($myrow = DB_fetch_array($result)) {
        array_push($Supplies, $myrow);
        $i++;
    }
    //end of while loop
    // Go through all requirements and check if have supplies to cover them
    $RequirementCount = count($Requirements);
    $SupplyCount = count($Supplies);
    $reqi = 0;
    //Index for requirements
    $supi = 0;
    // index for supplies
    $TotalRequirement = 0;
    $TotalSupply = 0;
    if ($RequirementCount > 0 && $SupplyCount > 0) {
        $TotalRequirement += $Requirements[$reqi]['quantity'];
        $TotalSupply += $Supplies[$supi]['supplyquantity'];
        while ($TotalRequirement > 0 && $TotalSupply > 0) {
            $Supplies[$supi]['updateflag'] = 1;
            // ******** Put leeway calculation in here ********
            $DueDate = ConvertSQLDate($Supplies[$supi]['duedate']);
            $ReqDate = ConvertSQLDate($Requirements[$reqi]['daterequired']);
            $DateDiff = DateDiff($DueDate, $ReqDate, 'd');
            //if ($Supplies[$supi]['duedate'] > $Requirements[$reqi]['daterequired']) {
            if ($DateDiff > abs(filter_number_format($_POST['Leeway']))) {
                $sql = "UPDATE mrpsupplies SET mrpdate = '" . $Requirements[$reqi]['daterequired'] . "' WHERE id = '" . $Supplies[$supi]['id'] . "' AND duedate = mrpdate";
                $result = DB_query($sql, $db);
            }
            if ($TotalRequirement > $TotalSupply) {
                $TotalRequirement -= $TotalSupply;
                $Requirements[$reqi]['quantity'] -= $TotalSupply;
                $TotalSupply = 0;
                $Supplies[$supi]['supplyquantity'] = 0;
                $supi++;
                if ($SupplyCount > $supi) {
                    $TotalSupply += $Supplies[$supi]['supplyquantity'];
                }
            } elseif ($TotalRequirement < $TotalSupply) {
                $TotalSupply -= $TotalRequirement;
                $Supplies[$supi]['supplyquantity'] -= $TotalRequirement;
                $TotalRequirement = 0;
                $Requirements[$reqi]['quantity'] = 0;
                $reqi++;
                if ($RequirementCount > $reqi) {
                    $TotalRequirement += $Requirements[$reqi]['quantity'];
                }
            } else {
                $TotalSupply -= $TotalRequirement;
                $Supplies[$supi]['supplyquantity'] -= $TotalRequirement;
                $TotalRequirement = 0;
                $Requirements[$reqi]['quantity'] = 0;
                $reqi++;
                if ($RequirementCount > $reqi) {
                    $TotalRequirement += $Requirements[$reqi]['quantity'];
                }
                $TotalRequirement -= $TotalSupply;
                $Requirements[$reqi]['quantity'] -= $TotalSupply;
                $TotalSupply = 0;
                $Supplies[$supi]['supplyquantity'] = 0;
                $supi++;
                if ($SupplyCount > $supi) {
                    $TotalSupply += $Supplies[$supi]['supplyquantity'];
                }
            }
            // End of if $TotalRequirement > $TotalSupply
        }
        // End of while
    }
    // End of if
    // When get to this part of code, have gone through all requirements, If there is any
    // unmet requirements, create an mrpplannedorder to cover it. Also call the
    // CreateLowerLevelRequirement() function to create gross requirements for lower level parts.
    // There is an excess quantity if the eoq is higher than the actual required amount.
    // If there is a subsuquent requirement, the excess quantity is subtracted from that
    // quantity. For instance, if the first requirement was for 2 and the eoq was 5, there
    // would be an excess of 3; if there was another requirement for 3 or less, the excess
    // would cover it, so no planned order would have to be created for the second requirement.
    $ExcessQty = 0;
    foreach ($Requirements as $key => $row) {
        $DateRequired[$key] = $row['daterequired'];
    }
    if (count($Requirements)) {
        array_multisort($DateRequired, SORT_ASC, $Requirements);
    }
    foreach ($Requirements as $Requirement) {
        // First, inflate requirement if there is a shrinkage factor
        // Should the quantity be rounded?
        if ($_POST['ShrinkageFlag'] == 'y' and $ShrinkFactor > 0) {
            $Requirement['quantity'] = $Requirement['quantity'] * 100 / (100 - $ShrinkFactor);
            $Requirement['quantity'] = round($Requirement['quantity'], $DecimalPlaces);
        }
        if ($ExcessQty >= $Requirement['quantity']) {
            $PlannedQty = 0;
            $ExcessQty -= $Requirement['quantity'];
        } else {
            $PlannedQty = $Requirement['quantity'] - $ExcessQty;
            $ExcessQty = 0;
        }
        if ($PlannedQty > 0) {
            if ($_POST['EOQFlag'] == 'y' and $eoq > $PlannedQty) {
                $ExcessQty = $eoq - $PlannedQty;
                $PlannedQty = $eoq;
            }
            // Pansize calculation here
            // if $PlannedQty not evenly divisible by $PanSize, calculate as $PlannedQty
            // divided by $PanSize and rounded up to the next highest integer and then
            // multiplied by the pansize. For instance, with a planned qty of 17 with a pansize
            // of 5, divide 17 by 5 to get 3 with a remainder of 2, which is rounded up to 4
            // and then multiplied by 5 - the pansize - to get 20
            if ($_POST['PanSizeFlag'] == 'y' and $PanSize != 0 and $PlannedQty != 0) {
                $PlannedQty = ceil($PlannedQty / $PanSize) * $PanSize;
            }
            // Calculate required date by subtracting leadtime from top part's required date
            $PartRequiredDate = $Requirement['daterequired'];
            if ((int) $LeadTime > 0) {
                $CalendarSQL = "SELECT COUNT(*),cal2.calendardate\n\t\t\t\t\t\t  FROM mrpcalendar\n\t\t\t\t\t\t\tLEFT JOIN mrpcalendar as cal2\n\t\t\t\t\t\t\t  ON (mrpcalendar.daynumber - '" . $LeadTime . "') = cal2.daynumber\n\t\t\t\t\t\t  WHERE mrpcalendar.calendardate = '" . $PartRequiredDate . "'\n\t\t\t\t\t\t\tAND cal2.manufacturingflag='1'\n\t\t\t\t\t\t\tGROUP BY cal2.calendardate";
                $ResultDate = DB_query($CalendarSQL, $db);
                $myrowdate = DB_fetch_array($ResultDate);
                $NewDate = $myrowdate[1];
                // If can't find date based on manufacturing calendar, use $PartRequiredDate
            } else {
                // Convert $PartRequiredDate from mysql format to system date format, use that to subtract leadtime
                // from it using DateAdd, convert that date back to mysql format
                $ConvertDate = ConvertSQLDate($PartRequiredDate);
                $DateAdd = DateAdd($ConvertDate, 'd', $LeadTime * -1);
                $NewDate = FormatDateForSQL($DateAdd);
            }
            $sql = "INSERT INTO mrpplannedorders (id,\n\t\t\t\t\t\t\t\t\t\t\t\tpart,\n\t\t\t\t\t\t\t\t\t\t\t\tduedate,\n\t\t\t\t\t\t\t\t\t\t\t\tsupplyquantity,\n\t\t\t\t\t\t\t\t\t\t\t\tordertype,\n\t\t\t\t\t\t\t\t\t\t\t\torderno,\n\t\t\t\t\t\t\t\t\t\t\t\tmrpdate,\n\t\t\t\t\t\t\t\t\t\t\t\tupdateflag)\n\t\t\t\t\t\t\t\t\t\t\tVALUES (NULL,\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $Requirement['part'] . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $NewDate . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $PlannedQty . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $Requirement['mrpdemandtype'] . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $Requirement['orderno'] . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'" . $NewDate . "',\n\t\t\t\t\t\t\t\t\t\t\t\t'0')";
            $result = DB_query($sql, $db);
            // If part has lower level components, create requirements for them
            $sql = "SELECT COUNT(*) FROM bom\n\t\t\t\t\t  WHERE parent ='" . $Requirement['part'] . "'\n\t\t\t\t\t  GROUP BY parent";
            $result = DB_query($sql, $db);
            $myrow = DB_fetch_row($result);
            if ($myrow[0] > 0) {
                CreateLowerLevelRequirement($db, $Requirement['part'], $Requirement['daterequired'], $PlannedQty, $Requirement['mrpdemandtype'], $Requirement['orderno'], $Requirement['whererequired']);
            }
        }
        // End of if $PlannedQty > 0
    }
    // End of foreach $Requirements
    // If there are any supplies not used and updateflag is zero, those supplies are not
    // necessary, so change date
    foreach ($Supplies as $supply) {
        if ($supply['supplyquantity'] > 0 && $supply['updateflag'] == 0) {
            $id = $supply['id'];
            $sql = "UPDATE mrpsupplies SET mrpdate ='2050-12-31' WHERE id = '" . $id . "'\n\t\t\t\t\t  AND ordertype <> 'QOH'";
            $result = DB_query($sql, $db);
        }
    }
}
      */
     $SQLTestExists = "SELECT price FROM prices\n\t\t\t\t\t\t\t\tWHERE stockid = '" . $_POST['StockID_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\tAND prices.typeabbrev ='" . $_POST['SalesType'] . "'\n\t\t                    \tAND prices.currabrev ='" . $_POST['CurrCode'] . "'\n\t\t\t\t\t\t\t\tAND prices.debtorno ='" . $_POST['DebtorNo_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\tAND prices.branchcode ='" . $_POST['BranchCode_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\tAND prices.startdate ='" . $_POST['StartDate_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\tAND prices.enddate ='" . $_POST['EndDate_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\tAND prices.price ='" . filter_number_format($_POST['Price_' . $PriceCounter]) . "'";
     $TestExistsResult = DB_query($SQLTestExists);
     if (DB_num_rows($TestExistsResult) == 0) {
         //the price doesn't currently exist
         //now check to see if a new price has already been created from start date of today
         $SQLTestExists = "SELECT price FROM prices\n\t\t\t\t\t\t\t\t\tWHERE stockid = '" . $_POST['StockID_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\t\tAND prices.typeabbrev ='" . $_POST['SalesType'] . "'\n\t\t\t                    \tAND prices.currabrev ='" . $_POST['CurrCode'] . "'\n\t\t\t\t\t\t\t\t\tAND prices.debtorno ='" . $_POST['DebtorNo_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\t\tAND prices.branchcode ='" . $_POST['BranchCode_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\t\tAND prices.startdate ='" . date('Y-m-d') . "'";
         $TestExistsResult = DB_query($SQLTestExists);
         if (DB_num_rows($TestExistsResult) == 1) {
             //then we are updating
             $SQLUpdate = "UPDATE prices\tSET price = '" . filter_number_format($_POST['Price_' . $PriceCounter]) . "'\n\t\t\t\t\t\t\t\t\tWHERE stockid = '" . $_POST['StockID_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\t\tAND prices.typeabbrev ='" . $_POST['SalesType'] . "'\n\t\t\t\t\t\t\t\t\tAND prices.currabrev ='" . $_POST['CurrCode'] . "'\n\t\t\t\t\t\t\t\t\tAND prices.debtorno ='" . $_POST['DebtorNo_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\t\tAND prices.branchcode ='" . $_POST['BranchCode_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\t\tAND prices.startdate ='" . date('Y-m-d') . "'\n\t\t\t\t\t\t\t\t\tAND prices.enddate ='" . $_POST['EndDate_' . $PriceCounter] . "'";
             $ResultUpdate = DB_query($SQLUpdate);
         } else {
             //there is not a price already starting today so need to create one
             //update the old price to have an end date of yesterday too
             $SQLUpdate = "UPDATE prices\tSET enddate = '" . FormatDateForSQL(DateAdd(Date($_SESSION['DefaultDateFormat']), 'd', -1)) . "'\n\t\t\t\t\t\t\t\t\tWHERE stockid = '" . $_POST['StockID_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\t\tAND prices.typeabbrev ='" . $_POST['SalesType'] . "'\n\t\t\t\t\t\t\t\t\tAND prices.currabrev ='" . $_POST['CurrCode'] . "'\n\t\t\t\t\t\t\t\t\tAND prices.debtorno ='" . $_POST['DebtorNo_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\t\tAND prices.branchcode ='" . $_POST['BranchCode_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\t\tAND prices.startdate ='" . $_POST['StartDate_' . $PriceCounter] . "'\n\t\t\t\t\t\t\t\t\tAND prices.enddate ='" . $_POST['EndDate_' . $PriceCounter] . "'";
             $Result = DB_query($SQLUpdate);
             //we need to add a new price from today
             $SQLInsert = "INSERT INTO prices (\tstockid,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tprice,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\ttypeabbrev,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcurrabrev,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tdebtorno,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tbranchcode,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tstartdate\n\t\t\t\t\t\t\t\t\t\t\t\t\t) VALUES (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $_POST['StockID_' . $PriceCounter] . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . filter_number_format($_POST['Price_' . $PriceCounter]) . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $_POST['SalesType'] . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $_POST['CurrCode'] . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $_POST['DebtorNo_' . $PriceCounter] . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . $_POST['BranchCode_' . $PriceCounter] . "',\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t'" . date('Y-m-d') . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t)";
             $ResultInsert = DB_query($SQLInsert);
         }
     }
     $PriceCounter++;
 }
 //end while loop
 DB_free_result($result);
 //clear the old result
 $result = DB_query($sql);
 //re-run the query with the updated prices
 $numrow = DB_num_rows($result);
 // get the new number - should be the same!!
Example #17
0
function AddOneMonth($dDate)
{
    return DateAdd("m", 1, $dDate);
}
                             }
                             array_push($booking_controllers[3], $fields);
                             break;
                         case DateAdd(4):
                             if (!isset($booking_controllers[4])) {
                                 $booking_controllers[4] = array();
                             }
                             array_push($booking_controllers[4], $fields);
                             break;
                         case DateAdd(5):
                             if (!isset($booking_controllers[5])) {
                                 $booking_controllers[5] = array();
                             }
                             array_push($booking_controllers[5], $fields);
                             break;
                         case DateAdd(6):
                             if (!isset($booking_controllers[6])) {
                                 $booking_controllers[6] = array();
                             }
                             array_push($booking_controllers[6], $fields);
                             break;
                     }
                 }
             } else {
                 if (checkCountryIcao(substr($fields[11], 0, 2)) or checkCountryIcao(substr($fields[13], 0, 2))) {
                     array_push($booking_pilots, $fields);
                 }
             }
             break;
     }
 }
Example #19
0
 /** loads the selected and given values to the form
  * this methods loads the selected and given values to the form from the material item or the form_post data
  */
 function _prepareValues()
 {
     $current_context = $this->_environment->getCurrentContextItem();
     $this->_values = array();
     if (!empty($this->_form_post)) {
         $this->_form_post['end_date_time'] = array();
         $this->_form_post['end_date_time'][] = !empty($this->_form_post['dayEnd']) ? $this->_form_post['dayEnd'] : NULL;
         $this->_form_post['end_date_time'][] = !empty($this->_form_post['timeEnd']) ? $this->_form_post['timeEnd'] : NULL;
         unset($this->_form_post['dayEnd']);
         unset($this->_form_post['timeEnd']);
         $this->_values = $this->_form_post;
         $tmp_array = array();
         if (isset($this->_form_post['dayStart'])) {
             $tmp_array['dayStart'] = $this->_form_post['dayStart'];
         } else {
             $tmp_array['dayStart'] = '';
         }
         if (isset($this->_form_post['timeStart'])) {
             $tmp_array['timeStart'] = $this->_form_post['timeStart'];
         } else {
             $tmp_array['timeStart'] = '';
         }
         $this->_values['start_date_time'] = $tmp_array;
     } elseif (isset($this->_item)) {
         $this->_values['iid'] = $this->_item->getItemID();
         $this->_values['title'] = $this->_item->getTitle();
         $this->_values['description'] = $this->_item->getDescription();
         $this->_values['public'] = $this->_item->isPublic();
         if (!$this->_item->getSeconddateTime() == '') {
             $this->_values['end_date_time'][] = getDateInLang($this->_item->getSeconddateTime());
         } else {
             $this->_values['end_date_time'][] = '';
         }
         if (!$this->_item->getSeconddateTime() == '') {
             $this->_values['end_date_time'][] = getTimeInLang($this->_item->getSeconddateTime());
         } else {
             $this->_values['end_date_time'][] = '';
         }
         $this->_setValuesForRubricConnections();
         // file
         $file_array = array();
         $file_list = $this->_item->getFileList();
         if ($file_list->getCount() > 0) {
             $file_item = $file_list->getFirst();
             while ($file_item) {
                 $file_array[] = $file_item->getFileID();
                 $file_item = $file_list->getNext();
             }
         }
         if (isset($this->_form_post['filelist'])) {
             $this->_values['filelist'] = $this->_form_post['filelist'];
         } else {
             $this->_values['filelist'] = $file_array;
         }
         if ($current_context->withActivatingContent()) {
             if ($this->_item->isPrivateEditing()) {
                 $this->_values['private_editing'] = 1;
             } else {
                 $this->_values['private_editing'] = $this->_item->isPrivateEditing();
             }
         } else {
             $this->_values['public'] = $this->_item->isPublic();
         }
         $this->_values['hide'] = $this->_item->isNotActivated() ? '1' : '0';
         if ($this->_item->isNotActivated()) {
             $activating_date = $this->_item->getActivatingDate();
             if (!strstr($activating_date, '9999-00-00')) {
                 $array = array();
                 $array['dayStart'] = getDateInLang($activating_date);
                 $array['timeStart'] = getTimeInLang($activating_date);
                 $this->_values['start_date_time'] = $array;
             }
         }
     } else {
         if ($this->_environment->inProjectRoom()) {
             $context_item = $this->_environment->getCurrentContextItem();
             $time = $context_item->getTimeSpread();
             $this->_values['end_date_time'][] = getDateInLang(DateAdd($time, date("Y-m-d"), "Y-m-d"));
             $this->_values['end_date_time'][] = date("H:m");
         }
         if ($current_context->withActivatingContent()) {
             if (!isset($this->_values['private_editing'])) {
                 $this->_values['private_editing'] = ($this->_environment->inProjectRoom() or $this->_environment->inGroupRoom()) ? '0' : '1';
                 //In projectrooms everybody can edit the item by default, else default is creator only
             }
         } else {
             if (!isset($this->_values['public'])) {
                 $this->_values['public'] = ($this->_environment->inProjectRoom() or $this->_environment->inGroupRoom()) ? '1' : '0';
                 //In projectrooms everybody can edit the item by default, else default is creator only
             }
         }
     }
 }
Example #20
0
function CreateLowerLevelRequirement(&$db, $toppart, $topdate, $topquantity, $topmrpdemandtype, $toporderno, $whererequired)
{
    // Creates an mrprequirement based on the net requirement from the part above it in the bom
    $sql = "SELECT bom.component,\n                   bom.quantity,\n                   levels.leadtime,\n                   levels.eoq\n            FROM bom\n                 LEFT JOIN levels \n                   ON bom.component = levels.part\n            WHERE bom.parent = '{$toppart}'\n\t\t AND effectiveafter <= now() \n\t\t AND effectiveto >= now()";
    $resultbom = DB_query($sql, $db);
    while ($myrow = DB_fetch_array($resultbom)) {
        // Calculate required date by subtracting leadtime from top part's required date
        $leadtime = $myrow['leadtime'];
        // Following sql finds daynumber for the top part's required date, subtracts leadtime, and finds
        // a valid manufacturing date for the daynumber. There is only one valid manufacturing date
        // for each daynumber, but there could be several non-manufacturing dates for the
        // same daynumber. MRPCalendar.php maintains the manufacturing calendar.
        $calendarsql = "SELECT COUNT(*),cal2.calendardate \n\t                      FROM mrpcalendar \n\t                        LEFT JOIN mrpcalendar as cal2 \n\t                          ON (mrpcalendar.daynumber - {$leadtime}) = cal2.daynumber\n\t                      WHERE mrpcalendar.calendardate = '{$topdate}'\n\t                        AND cal2.manufacturingflag='1'";
        $resultdate = DB_query($calendarsql, $db);
        $myrowdate = DB_fetch_array($resultdate);
        $newdate = $myrowdate[1];
        // If can't find date based on manufacturing calendar, use $topdate
        if ($myrowdate[0] == 0) {
            // Convert $topdate from mysql format to system date format, use that to subtract leadtime
            // from it using DateAdd, convert that date back to mysql format
            $convertdate = ConvertSQLDate($topdate);
            $dateadd = DateAdd($convertdate, "d", $leadtime * -1);
            $newdate = FormatDateForSQL($dateadd);
        }
        $component = $myrow['component'];
        $extendedquantity = $myrow['quantity'] * $topquantity;
        if ($myrow['eoq'] > $extendedquantity) {
            $extendedquantity = $myrow['eoq'];
        }
        $sql = "INSERT INTO mrprequirements \n\t\t\t\t\t\t(part,\n\t\t\t\t\t\t daterequired,\n\t\t\t\t\t\t quantity,\n\t\t\t\t\t\t mrpdemandtype,\n\t\t\t\t\t\t orderno,\n\t\t\t\t\t\t directdemand,\n\t\t\t\t\t\t whererequired)\n\t\t\t   VALUES ('{$component}',\n\t\t\t\t\t  '{$newdate}',\n\t\t\t\t\t  '{$extendedquantity}',\n\t\t\t\t\t  '{$topmrpdemandtype}',\n\t\t\t\t\t  '{$toporderno}',\n\t\t\t\t\t  '0',\n\t\t\t\t\t  '{$whererequired}')";
        $result = DB_query($sql, $db);
    }
    //end of while loop
}
        }
        echo '<tr>
				<td>' . ConvertSQLDate($myrow['trandate']) . '</td>
				<td>' . $myrow['stockid'] . '</td>
				<td>' . $myrow['description'] . '</td>
				<td class="number">' . $myrow['quantity'] . '</td>
				<td class="number">' . number_format($myrow['value'], $_SESSION['Currencies'][$_SESSION['CompanyRecord']['currencydefault']]['DecimalPlaces']) . '</td>
			</tr>';
        $SubTotalQuantity += $myrow['quantity'];
        $SubTotalValue += $myrow['value'];
    }
}
echo '<tr><th colspan="5"></th></tr>';
echo '<tr><th colspan="5"></th></tr>';
echo '<tr><td colspan="2"></td>';
echo '<td>' . _('Total For') . ' ' . $DayNames[DayOfWeekFromSQLDate(DateAdd($LastDate, 'd', -1))] . ' ' . DateAdd(ConvertSQLDate($LastDate), 'd', 0) . '</td>';
echo '<td class="number">' . $SubTotalQuantity . '</td>';
echo '<td class="number">' . number_format($SubTotalValue, $_SESSION['Currencies'][$_SESSION['CompanyRecord']['currencydefault']]['DecimalPlaces']) . '</td></tr>';
echo '<tr><th colspan="5"></th></tr>';
echo '<tr><th colspan="5"></th></tr>';
echo '<tr><td colspan="2"></td>';
echo '<td><b>' . 'Total' . '</b></td>';
echo '<td class="number"><b>' . $TotalQuantity . '</b></td>';
echo '<td class="number"><b>' . number_format($TotalValue, $_SESSION['Currencies'][$_SESSION['CompanyRecord']['currencydefault']]['DecimalPlaces']) . '</b></td></tr>';
echo '<tr><th colspan="5"></th></tr>';
echo '</table>';
echo '</td>';
echo '<td width="33%" style="text-align: left;vertical-align: top;">';
echo '<table width="100%" class="selection">';
$sql = "SELECT stockmoves.stockid,\n\t\t\t\tstockmaster.description,\n\t\t\t\tsum(-qty*price) AS value\n\t\t\tFROM stockmoves\n\t\t\tLEFT JOIN stockmaster\n\t\t\tON stockmaster.stockid=stockmoves.stockid\n\t\t\tLEFT JOIN stockcategory\n\t\t\tON stockmaster.categoryid=stockcategory.categoryid\n\t\t\tWHERE stockcategory.stocktype='X'\n\t\t\t\tAND stockmoves.trandate='" . FormatDateForSQL($_POST['ReportDate']) . "'\n\t\t\tGROUP BY stockmoves.stockid";
$result = DB_query($sql, $db);
Example #22
0
         // Day +1 ???????? Dont know why so far - maybe the timezone
         $auction_offer_time_stop = mktime(0, 0, 0, $HTTP_POST_VARS['auction_offer_time_stop_m'], $HTTP_POST_VARS['auction_offer_time_stop_d'] + 1, $HTTP_POST_VARS['auction_offer_time_stop_y']);
         $auction_offer_time_start = mktime(0, 0, 0, $HTTP_POST_VARS['auction_offer_time_start_m'], $HTTP_POST_VARS['auction_offer_time_start_d'] + 1, $HTTP_POST_VARS['auction_offer_time_start_y']);
     } else {
         checkAuctionDatesStart($HTTP_POST_VARS['auction_offer_time_start_m'], $HTTP_POST_VARS['auction_offer_time_start_d'], $HTTP_POST_VARS['auction_offer_time_start_y']);
         $auction_offer_time_start = mktime(0, 0, 0, $HTTP_POST_VARS['auction_offer_time_start_m'], $HTTP_POST_VARS['auction_offer_time_start_d'] + 1, $HTTP_POST_VARS['auction_offer_time_start_y']);
         $auction_offer_time_stop = DateAdd('d', $HTTP_POST_VARS['time_to_end_dd'], $auction_offer_time_start);
     }
 } else {
     if ($HTTP_POST_VARS['time_to_end_dd'] == 0) {
         checkAuctionDatesStop($HTTP_POST_VARS['auction_offer_time_stop_m'], $HTTP_POST_VARS['auction_offer_time_stop_d'], $HTTP_POST_VARS['auction_offer_time_stop_y']);
         $auction_offer_time_start = time();
         $auction_offer_time_stop = mktime(0, 0, 0, $HTTP_POST_VARS['auction_offer_time_stop_m'], $HTTP_POST_VARS['auction_offer_time_stop_d'] + 1, $HTTP_POST_VARS['auction_offer_time_stop_y']);
     } else {
         $auction_offer_time_start = time();
         $auction_offer_time_stop = DateAdd('d', $HTTP_POST_VARS['time_to_end_dd'], time());
     }
 }
 // END DATE-Handling
 $pic_upload = 0;
 // get the config data
 if ($HTTP_POST_FILES['auction_offer_picture_file']['size'] > 0) {
     // If the include does not exist we exit
     if (!file_exists($phpbb_root_path . 'auction/graphic_files/auction_pic_upload.' . $phpEx)) {
         message_die(GENERAL_ERROR, $lang['auction_pic_upload_missing']);
     } else {
         // we fetch the image parameters
         $auction_config_pic = init_auction_config_pic();
         // we include the upload file
         // all the upload work is done there
         include $phpbb_root_path . 'auction/graphic_files/auction_pic_upload.' . $phpEx;
function submit(&$db, &$ChangeDate)
{
    //initialize no input errors
    $InputError = 0;
    /* actions to take once the user has clicked the submit button
    	ie the page has called itself with some user input */
    //first off validate inputs sensible
    if (!Is_Date($_POST['FromDate'])) {
        $InputError = 1;
        prnMsg(_('Invalid From Date'), 'error');
    }
    if (!Is_Date($_POST['ToDate'])) {
        $InputError = 1;
        prnMsg(_('Invalid To Date'), 'error');
    }
    // Use FormatDateForSQL to put the entered dates into right format for sql
    // Use ConvertSQLDate to put sql formatted dates into right format for functions such as
    // DateDiff and DateAdd
    $FormatFromDate = FormatDateForSQL($_POST['FromDate']);
    $FormatToDate = FormatDateForSQL($_POST['ToDate']);
    $ConvertFromDate = ConvertSQLDate($FormatFromDate);
    $ConvertToDate = ConvertSQLDate($FormatToDate);
    $DateGreater = Date1GreaterThanDate2($_POST['ToDate'], $_POST['FromDate']);
    $DateDiff = DateDiff($ConvertToDate, $ConvertFromDate, 'd');
    // Date1 minus Date2
    if ($DateDiff < 1) {
        $InputError = 1;
        prnMsg(_('To Date Must Be Greater Than From Date'), 'error');
    }
    if ($InputError == 1) {
        ShowInputForm($db, $ChangeDate);
        return;
    }
    $sql = "DROP TABLE IF EXISTS mrpcalendar";
    $result = DB_query($sql);
    $sql = "CREATE TABLE mrpcalendar (\n\t\t\t\tcalendardate date NOT NULL,\n\t\t\t\tdaynumber int(6) NOT NULL,\n\t\t\t\tmanufacturingflag smallint(6) NOT NULL default '1',\n\t\t\t\tINDEX (daynumber),\n\t\t\t\tPRIMARY KEY (calendardate)) DEFAULT CHARSET=utf8";
    $ErrMsg = _('The SQL to create passbom failed with the message');
    $result = DB_query($sql, $ErrMsg);
    $i = 0;
    /* $DaysTextArray used so can get text of day based on the value get from DayOfWeekFromSQLDate of
    	 the calendar date. See if that text is in the ExcludeDays array note no gettext here hard coded english days from $_POST*/
    $DaysTextArray = array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday');
    $ExcludeDays = array($_POST['Sunday'], $_POST['Monday'], $_POST['Tuesday'], $_POST['Wednesday'], $_POST['Thursday'], $_POST['Friday'], $_POST['Saturday']);
    $CalDate = $ConvertFromDate;
    for ($i = 0; $i <= $DateDiff; $i++) {
        $DateAdd = FormatDateForSQL(DateAdd($CalDate, 'd', $i));
        // If the check box for the calendar date's day of week was clicked, set the manufacturing flag to 0
        $DayOfWeek = DayOfWeekFromSQLDate($DateAdd);
        $ManuFlag = 1;
        foreach ($ExcludeDays as $exday) {
            if ($exday == $DaysTextArray[$DayOfWeek]) {
                $ManuFlag = 0;
            }
        }
        $sql = "INSERT INTO mrpcalendar (\n\t\t\t\t\tcalendardate,\n\t\t\t\t\tdaynumber,\n\t\t\t\t\tmanufacturingflag)\n\t\t\t\t VALUES ('" . $DateAdd . "',\n\t\t\t\t\t\t'1',\n\t\t\t\t\t\t'" . $ManuFlag . "')";
        $result = DB_query($sql, $ErrMsg);
    }
    // Update daynumber. Set it so non-manufacturing days will have the same daynumber as a valid
    // manufacturing day that precedes it. That way can read the table by the non-manufacturing day,
    // subtract the leadtime from the daynumber, and find the valid manufacturing day with that daynumber.
    $DayNumber = 1;
    $sql = "SELECT * FROM mrpcalendar\n\t\t\tORDER BY calendardate";
    $result = DB_query($sql, $ErrMsg);
    while ($myrow = DB_fetch_array($result)) {
        if ($myrow['manufacturingflag'] == "1") {
            $DayNumber++;
        }
        $CalDate = $myrow['calendardate'];
        $sql = "UPDATE mrpcalendar SET daynumber = '" . $DayNumber . "'\n\t\t\t\t\tWHERE calendardate = '" . $CalDate . "'";
        $resultupdate = DB_query($sql, $ErrMsg);
    }
    prnMsg(_('The MRP Calendar has been created'), 'success');
    ShowInputForm($db, $ChangeDate);
}
Example #24
0
<?php

/* $Revision: 1.2 $ */
/* $Id: PDFTopItems.php 4495 2011-02-22 09:45:01Z daintree $*/
include 'includes/session.inc';
include 'includes/PDFStarter.php';
$FontSize = 10;
$pdf->addInfo('Title', _('Top Items Search Result'));
$PageNumber = 1;
$line_height = 12;
include 'includes/PDFTopItemsHeader.inc';
$FontSize = 10;
$FromDate = FormatDateForSQL(DateAdd(Date($_SESSION['DefaultDateFormat']), 'd', -$_GET['NumberOfDays']));
//the situation if the location and customer type selected "All"
if ($_GET['Location'] == 'All' and $_GET['Customers'] == 'All') {
    $SQL = "SELECT \tsalesorderdetails.stkcode,\n\t\t\t\tSUM(salesorderdetails.qtyinvoiced) totalinvoiced,\n\t\t\t\tSUM(salesorderdetails.qtyinvoiced * salesorderdetails.unitprice ) AS valuesales,\n\t\t\t\tstockmaster.description,\n\t\t\t\tstockmaster.decimalplaces,\n\t\t\t\tdebtorsmaster.currcode,\n\t\t\t\tstockmaster.units\n\t\t\tFROM \tsalesorderdetails, salesorders, debtorsmaster,stockmaster\n\t\t\tWHERE \tsalesorderdetails.orderno = salesorders.orderno\n\t\t\t\tAND salesorderdetails.stkcode = stockmaster.stockid\n\t\t\t\tAND salesorders.debtorno = debtorsmaster.debtorno\n\t\t\t\tAND salesorderdetails.actualdispatchdate >='" . $FromDate . "'\n\t\t\tGROUP BY salesorderdetails.stkcode\n\t\t\tORDER BY '" . $_GET['Sequence'] . "' DESC\n\t\t\tLIMIT " . $_GET['NumberOfTopItems'];
} else {
    //the situation if only location type selected "All"
    if ($_GET['Location'] == 'All') {
        $SQL = "SELECT \tsalesorderdetails.stkcode,\n\t\t\t\t\tSUM(salesorderdetails.qtyinvoiced) totalinvoiced,\n\t\t\t\t\tSUM(salesorderdetails.qtyinvoiced * salesorderdetails.unitprice ) AS valuesales,\n\t\t\t\t\tstockmaster.description,\n\t\t\t\t\tstockmaster.decimalplaces,\n\t\t\t\t\tdebtorsmaster.currcode,\n\t\t\t\t\tstockmaster.units\n\t\t\t\tFROM \tsalesorderdetails, salesorders, debtorsmaster,stockmaster\n\t\t\t\tWHERE \tsalesorderdetails.orderno = salesorders.orderno\n\t\t\t\t\t\tAND salesorderdetails.stkcode = stockmaster.stockid\n\t\t\t\t\t\tAND salesorders.debtorno = debtorsmaster.debtorno\n\t\t\t\t\t\tAND debtorsmaster.typeid = '" . $_GET['Customers'] . "'\n\t\t\t\t\t\tAND salesorderdetails.ActualDispatchDate >= '" . $FromDate . "'\n\t\t\t\tGROUP BY salesorderdetails.stkcode\n\t\t\t\tORDER BY '" . $_GET['Sequence'] . "' DESC\n\t\t\t\tLIMIT " . $_GET['NumberOfTopItems'];
    } else {
        //the situation if the customer type selected "All"
        if ($_GET['Customers'] == 'All') {
            $SQL = "SELECT \tsalesorderdetails.stkcode,\n\t\t\t\t\t\tSUM(salesorderdetails.qtyinvoiced) totalinvoiced,\n\t\t\t\t\t\tSUM(salesorderdetails.qtyinvoiced * salesorderdetails.unitprice ) AS valuesales,\n\t\t\t\t\t\tstockmaster.description,\n\t\t\t\t\t\tstockmaster.decimalplaces,\n\t\t\t\t\t\tdebtorsmaster.currcode,\n\t\t\t\t\t\tstockmaster.units\n\t\t\t\t\tFROM \tsalesorderdetails, salesorders, debtorsmaster,stockmaster\n\t\t\t\t\tWHERE \tsalesorderdetails.orderno = salesorders.orderno\n\t\t\t\t\t\tAND salesorderdetails.stkcode = stockmaster.stockid\n\t\t\t\t\t\tAND salesorders.debtorno = debtorsmaster.debtorno\n\t\t\t\t\t\tAND salesorders.fromstkloc = '" . $_GET['Location'] . "'\n\t\t\t\t\t\tAND salesorderdetails.ActualDispatchDate >= '" . $FromDate . "'\n\t\t\t\t\tGROUP BY salesorderdetails.stkcode\n\t\t\t\t\tORDER BY '" . $_GET['Sequence'] . "' DESC\n\t\t\t\t\tLIMIT 0," . $_GET['NumberOfTopItems'];
        } else {
            //the situation if the location and customer type not selected "All"
            $SQL = "SELECT \tsalesorderdetails.stkcode,\n\t\t\t\t\t\tSUM(salesorderdetails.qtyinvoiced) totalinvoiced,\n\t\t\t\t\t\tSUM(salesorderdetails.qtyinvoiced * salesorderdetails.unitprice ) AS valuesales,\n\t\t\t\t\t\tstockmaster.description,\n\t\t\t\t\t\tstockmaster.decimalplaces,\n\t\t\t\t\t\tdebtorsmaster.currcode,\n\t\t\t\t\t\tstockmaster.units\n\t\t\t\t\tFROM \tsalesorderdetails, salesorders, debtorsmaster,stockmaster\n\t\t\t\t\tWHERE \tsalesorderdetails.orderno = salesorders.orderno\n\t\t\t\t\t\tAND salesorderdetails.stkcode = stockmaster.stockid\n\t\t\t\t\t\tAND salesorders.debtorno = debtorsmaster.debtorno\n\t\t\t\t\t\tAND salesorders.fromstkloc = '" . $_GET['Location'] . "'\n\t\t\t\t\t\tAND debtorsmaster.typeid = '" . $_GET['Customers'] . "'\n\t\t\t\t\t\tAND salesorderdetails.actualdispatchdate >= '" . $FromDate . "'\n\t\t\t\t\tGROUP BY salesorderdetails.stkcode\n\t\t\t\t\tORDER BY '" . $_GET['Sequence'] . "' DESC\n\t\t\t\t\tLIMIT " . $_GET['NumberOfTopItems'];
        }
    }
}
$result = DB_query($SQL, $db);
Example #25
0
         $PurchRow = DB_fetch_array($PurchDataResult);
         $PurchPrice = $PurchRow['price'] / $PurchRow['conversionfactor'];
         $ConversionFactor = $PurchRow['conversionfactor'];
         $SupplierDescription = $PurchRow['suppliers_partno'] . ' - ';
         if (mb_strlen($PurchRow['supplierdescription']) > 2) {
             $SupplierDescription .= $PurchRow['supplierdescription'];
         } else {
             $SupplierDescription .= $ItemRow['description'];
         }
         $SuppliersUnitOfMeasure = $PurchRow['suppliersuom'];
         $SuppliersPartNo = $PurchRow['suppliers_partno'];
         $LeadTime = $PurchRow['leadtime'];
         /* Work out the delivery date based on today + lead time
          * if > header DeliveryDate then set DeliveryDate to today + leadtime
          */
         $DeliveryDate = DateAdd(Date($_SESSION['DefaultDateFormat']), 'd', $LeadTime);
         if (!Date1GreaterThanDate2($DeliveryDate, $_SESSION['PO' . $identifier]->DeliveryDate)) {
             $DeliveryDate = $_SESSION['PO' . $identifier]->DeliveryDate;
         }
     } else {
         // no purchasing data setup
         $PurchPrice = 0;
         $ConversionFactor = 1;
         $SupplierDescription = $ItemRow['description'];
         $SuppliersUnitOfMeasure = $ItemRow['units'];
         $SuppliersPartNo = '';
         $LeadTime = 1;
         $DeliveryDate = $_SESSION['PO' . $identifier]->DeliveryDate;
     }
     $_SESSION['PO' . $identifier]->add_to_order($_SESSION['PO' . $identifier]->LinesOnOrder + 1, $ItemCode, 0, 0, filter_number_format($Quantity) * $ConversionFactor, $SupplierDescription, $PurchPrice, $ItemRow['units'], $ItemRow['stockact'], $DeliveryDate, 0, 0, 0, 0, 0, $ItemRow['accountname'], $ItemRow['decimalplaces'], $SuppliersUnitOfMeasure, $ConversionFactor, $LeadTime, $SuppliersPartNo);
 } else {
Example #26
0
         $Order_Value = 0;
         /*Now get all the required details for the supplier */
         $sql = "SELECT address1,\n\t \t\t\t\t\t\t\taddress2,\n\t \t\t\t\t\t\t\taddress3,\n\t \t\t\t\t\t\t\taddress4,\n\t \t\t\t\t\t\t\taddress5,\n\t \t\t\t\t\t\t\taddress6,\n\t \t\t\t\t\t\t\ttelephone,\n\t \t\t\t\t\t\t\tpaymentterms,\n\t \t\t\t\t\t\t\tcurrcode,\n\t \t\t\t\t\t\t\trate\n\t\t\t\t\t\t FROM suppliers INNER JOIN currencies\n\t\t\t\t\t\t    ON suppliers.currcode = currencies.currabrev\n\t\t\t\t\t\t    WHERE supplierid='" . $SupplierID . "'";
         $ErrMsg = _('Could not get the supplier information for the order');
         $SuppResult = DB_query($sql, $ErrMsg);
         $SuppRow = DB_fetch_array($SuppResult);
         $StatusComment = date($_SESSION['DefaultDateFormat']) . ' - ' . _('Order Created by') . ' ' . $UserDetails . ' - ' . _('Auto created from sales orders') . '<br />';
         /*Insert to purchase order header record */
         $sql = "INSERT INTO purchorders ( orderno,\n\t\t  \t\t\t\t\t\t\t\t\t  supplierno,\n\t\t  \t\t\t\t\t\t\t\t\t  orddate,\n\t\t  \t\t\t\t\t\t\t\t\t  rate,\n\t\t  \t\t\t\t\t\t\t\t\t  initiator,\n\t\t  \t\t\t\t\t\t\t\t\t  intostocklocation,\n\t\t  \t\t\t\t\t\t\t\t\t  deladd1,\n\t\t  \t\t\t\t\t\t\t\t\t  deladd2,\n\t\t  \t\t\t\t\t\t\t\t\t  deladd3,\n\t\t  \t\t\t\t\t\t\t\t\t  deladd4,\n\t\t  \t\t\t\t\t\t\t\t\t  deladd5,\n\t\t  \t\t\t\t\t\t\t\t\t  deladd6,\n\t\t  \t\t\t\t\t\t\t\t\t  tel,\n\t\t  \t\t\t\t\t\t\t\t\t  suppdeladdress1,\n\t\t  \t\t\t\t\t\t\t\t\t  suppdeladdress2,\n\t\t  \t\t\t\t\t\t\t\t\t  suppdeladdress3,\n\t\t  \t\t\t\t\t\t\t\t\t  suppdeladdress4,\n\t\t  \t\t\t\t\t\t\t\t\t  suppdeladdress5,\n\t\t  \t\t\t\t\t\t\t\t\t  suppdeladdress6,\n\t\t  \t\t\t\t\t\t\t\t\t  supptel,\n\t\t  \t\t\t\t\t\t\t\t\t  version,\n\t\t  \t\t\t\t\t\t\t\t\t  revised,\n\t\t  \t\t\t\t\t\t\t\t\t  deliveryby,\n\t\t  \t\t\t\t\t\t\t\t\t  status,\n\t\t  \t\t\t\t\t\t\t\t\t  stat_comment,\n\t\t  \t\t\t\t\t\t\t\t\t  deliverydate,\n\t\t  \t\t\t\t\t\t\t\t\t  paymentterms,\n\t\t  \t\t\t\t\t\t\t\t\t  allowprint)\n\t\t  \t\t\t\t\t\t\t\t\tVALUES(\t'" . $PO_OrderNo . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $SupplierID . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . Date('Y-m-d') . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $SuppRow['rate'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $_SESSION['UserID'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $_SESSION['UserStockLocation'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $DelAddRow['locationname'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $DelAddRow['deladd1'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $DelAddRow['deladd2'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $DelAddRow['deladd3'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $DelAddRow['deladd4'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $DelAddRow['deladd5'] . ' ' . $DelAddRow['deladd6'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $DelAddRow['tel'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $SuppRow['address1'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $SuppRow['address2'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $SuppRow['address3'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $SuppRow['address4'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $SuppRow['address5'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $SuppRow['address6'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $SuppRow['telephone'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'1.0',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . Date('Y-m-d') . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $_SESSION['Default_Shipper'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'Pending',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $StatusComment . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . Date('Y-m-d') . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t'" . $SuppRow['paymentterms'] . "',\n\t\t  \t\t\t\t\t\t\t\t\t\t0)";
         $ErrMsg = _('The purchase order header record could not be inserted into the database because');
         $DbgMsg = _('The SQL statement used to insert the purchase order header record and failed was');
         $result = DB_query($sql, $ErrMsg, $DbgMsg, true);
     }
     //end if it's a new supplier and PO to create
     /*reminder we are in a loop of the total of each item to place a purchase order for based on a selection of sales orders */
     $DeliveryDate = DateAdd(Date($_SESSION['DefaultDateFormat']), 'd', $ItemRow['leadtime']);
     $sql = "INSERT INTO purchorderdetails ( orderno,\n\t\t      \t\t\t\t\t\t\t\t\titemcode,\n\t\t      \t\t\t\t\t\t\t\t\tdeliverydate,\n\t\t      \t\t\t\t\t\t\t\t\titemdescription,\n\t\t      \t\t\t\t\t\t\t\t\tglcode,\n\t\t      \t\t\t\t\t\t\t\t\tunitprice,\n\t\t      \t\t\t\t\t\t\t\t\tquantityord,\n\t\t      \t\t\t\t\t\t\t\t\tsuppliersunit,\n\t\t      \t\t\t\t\t\t\t\t\tsuppliers_partno,\n\t\t      \t\t\t\t\t\t\t\t\tconversionfactor )\n\t\t\t\t\t      VALUES ('" . $PO_OrderNo . "',\n\t\t      \t\t\t\t\t\t     '" . $ItemRow['stockid'] . "',\n\t\t      \t\t\t\t\t\t     '" . FormatDateForSQL($DeliveryDate) . "',\n\t\t      \t\t\t\t\t\t     '" . $ItemRow['suppliers_partno'] . '  ' . $ItemRow['supplierdescription'] . "',\n\t\t      \t\t\t\t\t\t     '" . $ItemRow['stockact'] . "',\n\t\t      \t\t\t\t\t\t     '" . $ItemRow['price'] . "',\n\t\t      \t\t\t\t\t\t     '" . $ItemRow['orderqty'] . "',\n\t\t      \t\t\t\t\t\t     '" . $ItemRow['suppliersuom'] . "',\n\t\t      \t\t\t\t\t\t     '" . $ItemRow['suppliers_partno'] . "',\n\t\t      \t\t\t\t\t\t     '" . $ItemRow['conversionfactor'] . "')";
     $ErrMsg = _('One of the purchase order detail records could not be inserted into the database because');
     $DbgMsg = _('The SQL statement used to insert the purchase order detail record and failed was');
     $result = DB_query($sql, $ErrMsg, $DbgMsg, true);
     $Order_Value += $ItemRow['price'] * $ItemRow['orderqty'];
 }
 /* end of the loop round the items on the sales order  that we wish to place purchase orders for */
 /* The last line to be purchase ordered was reach so there will be an order which is not yet completed in progress now to completed it */
 if ($SupplierID != '' and $_SESSION['AutoAuthorisePO'] == 1) {
     //if the user has authority to authorise the PO then it should be created as authorised
     $AuthSQL = "SELECT authlevel\n\t\t\t\t\t\t\tFROM purchorderauth\n\t\t\t\t\t\t\tWHERE userid='" . $_SESSION['UserID'] . "'\n\t\t\t\t\t\t\tAND currabrev='" . $SuppRow['currcode'] . "'";
     $AuthResult = DB_query($AuthSQL);
     $AuthRow = DB_fetch_array($AuthResult);
     if ($AuthRow['authlevel'] = '') {
         $AuthRow['authlevel'] = 0;
function ReSequenceEffectiveDates($Item, $PriceList, $CurrAbbrev, $CustomerID, $db)
{
    /*This is quite complicated - the idea is that prices set up should be unique and there is no way two prices could be returned as valid - when getting a price in includes/GetPrice.inc the logic is to first look for a price of the salestype/currency within the effective start and end dates - then if not get the price with a start date prior but a blank end date (the default price). We would not want two prices where the effective dates fall between an existing price so it is necessary to update enddates of prices  - with me - I am just hanging on here myself
    	 Prices with no end date are default prices and need to be ignored in this resquence*/
    $SQL = "SELECT branchcode,\n\t\t\t\t\t\tstartdate,\n\t\t\t\t\t\tenddate\n\t\t\t\t\t\tFROM prices\n\t\t\t\t\t\tWHERE debtorno='" . $CustomerID . "'\n\t\t\t\t\t\tAND stockid='" . $Item . "'\n\t\t\t\t\t\tAND currabrev='" . $CurrAbbrev . "'\n\t\t\t\t\t\tAND typeabbrev='" . $PriceList . "'\n\t\t\t\t\t\tAND enddate<>''\n\t\t\t\t\t\tORDER BY\n\t\t\t\t\t\tbranchcode,\n\t\t\t\t\t\tstartdate,\n\t\t\t\t\t\tenddate";
    $result = DB_query($SQL, $db);
    unset($BranchCode);
    while ($myrow = DB_fetch_array($result)) {
        if (!isset($BranchCode)) {
            unset($NextDefaultStartDate);
            //a price with a blank end date
            unset($NextStartDate);
            unset($EndDate);
            unset($StartDate);
            $BranchCode = $myrow['branchcode'];
        }
        if (isset($NextStartDate)) {
            if (Date1GreaterThanDate2(ConvertSQLDate($myrow['startdate']), $NextStartDate)) {
                $NextStartDate = ConvertSQLDate($myrow['startdate']);
                if (Date1GreaterThanDate2(ConvertSQLDate($EndDate), ConvertSQLDate($myrow['startdate']))) {
                    /*Need to make the end date the new start date less 1 day */
                    $SQL = "UPDATE prices SET enddate = '" . FormatDateForSQL(DateAdd($NextStartDate, 'd', -1)) . "'\n\t\t\t\t\t\t\t\t\t\tWHERE stockid ='" . $Item . "'\n\t\t\t\t\t\t\t\t\t\tAND currabrev='" . $CurrAbbrev . "'\n\t\t\t\t\t\t\t\t\t\tAND typeabbrev='" . $PriceList . "'\n\t\t\t\t\t\t\t\t\t\tAND startdate ='" . $StartDate . "'\n\t\t\t\t\t\t\t\t\t\tAND enddate = '" . $EndDate . "'\n\t\t\t\t\t\t\t\t\t\tAND debtorno ='" . $CustomerID . "'";
                    $UpdateResult = DB_query($SQL, $db);
                }
            }
            //end of if startdate  after NextStartDate - we have a new NextStartDate
        } else {
            $NextStartDate = ConvertSQLDate($myrow['startdate']);
        }
        $StartDate = $myrow['startdate'];
        $EndDate = $myrow['enddate'];
    }
}
    /*in this case default depreciation calc to the last day of last month - and allow user to select a period */
    if (!isset($_POST['ProcessDate'])) {
        $_POST['ProcessDate'] = Date($_SESSION['DefaultDateFormat'], mktime(0, 0, 0, date('m'), 0, date('Y')));
    } else {
        //ProcessDate is set - make sure it is on the last day of the month selected
        if (!Is_Date($_POST['ProcessDate'])) {
            prnMsg(_('The date is expected to be in the format') . ' ' . $_SESSION['DefaultDateFormat'], 'error');
            $InputError = true;
        } else {
            $_POST['ProcessDate'] = LastDayOfMonth($_POST['ProcessDate']);
        }
    }
} else {
    //depn calc has been run previously
    $AllowUserEnteredProcessDate = false;
    $_POST['ProcessDate'] = LastDayOfMonth(DateAdd(ConvertSQLDate($LastDepnRun[0]), 'd', 28));
}
/* Get list of assets for journal */
$sql = "SELECT fixedassets.assetid,\n\t\t\tfixedassets.description,\n\t\t\tfixedassets.depntype,\n\t\t\tfixedassets.depnrate,\n\t\t\tfixedassets.datepurchased,\n\t\t\tfixedassetcategories.accumdepnact,\n\t\t\tfixedassetcategories.depnact,\n\t\t\tfixedassetcategories.categorydescription,\n\t\t\tSUM(CASE WHEN fixedassettrans.fixedassettranstype='cost' THEN fixedassettrans.amount ELSE 0 END) AS costtotal,\n\t\t\tSUM(CASE WHEN fixedassettrans.fixedassettranstype='depn' THEN fixedassettrans.amount ELSE 0 END) AS depnbfwd\n\t\tFROM fixedassets\n\t\tINNER JOIN fixedassetcategories\n\t\t\tON fixedassets.assetcategoryid=fixedassetcategories.categoryid\n\t\tINNER JOIN fixedassettrans\n\t\t\tON fixedassets.assetid=fixedassettrans.assetid\n\t\tWHERE fixedassettrans.transdate<='" . FormatDateForSQL($_POST['ProcessDate']) . "'\n\t\tGROUP BY fixedassets.assetid,\n\t\t\tfixedassets.description,\n\t\t\tfixedassets.depntype,\n\t\t\tfixedassets.depnrate,\n\t\t\tfixedassets.datepurchased,\n\t\t\tfixedassetcategories.accumdepnact,\n\t\t\tfixedassetcategories.depnact,\n\t\t\tfixedassetcategories.categorydescription\n\t\tORDER BY assetcategoryid, assetid";
$AssetsResult = DB_query($sql, $db);
$InputError = false;
//always hope for the best
if (Date1GreaterThanDate2($_POST['ProcessDate'], Date($_SESSION['DefaultDateFormat']))) {
    prnMsg(_('No depreciation will be committed as the processing date is beyond the current date. The depreciation run can only be run for periods prior to today'), 'warn');
    $InputError = true;
}
if (isset($_POST['CommitDepreciation']) and $InputError == false) {
    $result = DB_Txn_Begin($db);
    $TransNo = GetNextTransNo(44, $db);
    $PeriodNo = GetPeriod($_POST['ProcessDate'], $db);
}
function ReSequenceEffectiveDates($Item, $PriceList, $CurrAbbrev, $QuantityBreak, $db)
{
    /*This is quite complicated - the idea is that prices set up should be unique and there is no way two prices could be returned as valid - when getting a price in includes/GetPrice.inc the logic is to first look for a price of the salestype/currency within the effective start and end dates - then if not get the price with a start date prior but a blank end date (the default price). We would not want two prices where one price falls inside another effective date range except in the case of a blank end date - ie no end date - the default price for the currency/salestype.
    	I first thought that we would need to update the previous default price (blank end date), when a new default price is entered, to have an end date of the startdate of this new default price less 1 day - but this is  converting a default price into a special price which could result in having two special prices over the same date range - best to leave it unchanged and use logic in the GetPrice.inc to ensure the correct default price is returned
    	*
    	* After further discussion (Ricard) if the new price has a blank end date - i.e. no end then the pre-existing price with no end date should be changed to have an end date just prior to the new default (no end date) price commencing
    	*/
    //this is just the case where debtorno='' - see the Prices_Customer.php script for customer special prices
    $SQL = "SELECT price,\r\n\t\t\t\t\t\tstartdate,\r\n\t\t\t\t\t\tenddate\r\n\t\t\t\tFROM pricematrix\r\n\t\t\t\tWHERE stockid='" . $Item . "'\r\n\t\t\t\tAND currabrev='" . $CurrAbbrev . "'\r\n\t\t\t\tAND salestype='" . $PriceList . "'\r\n\t\t\t\tAND quantitybreak='" . $QuantityBreak . "'\r\n\t\t\t\tORDER BY startdate, enddate";
    $result = DB_query($SQL);
    while ($myrow = DB_fetch_array($result)) {
        if (isset($NextStartDate)) {
            if (Date1GreaterThanDate2(ConvertSQLDate($myrow['startdate']), $NextStartDate)) {
                $NextStartDate = ConvertSQLDate($myrow['startdate']);
                //Only if the previous enddate is after the new start date do we need to look at updates
                if (Date1GreaterThanDate2(ConvertSQLDate($EndDate), ConvertSQLDate($myrow['startdate']))) {
                    /*Need to make the end date the new start date less 1 day */
                    $SQL = "UPDATE pricematrix SET enddate = '" . FormatDateForSQL(DateAdd($NextStartDate, 'd', -1)) . "'\r\n\t\t\t\t\t\t\t\t\t\tWHERE stockid ='" . $Item . "'\r\n\t\t\t\t\t\t\t\t\t\tAND currabrev='" . $CurrAbbrev . "'\r\n\t\t\t\t\t\t\t\t\t\tAND salestype='" . $PriceList . "'\r\n\t\t\t\t\t\t\t\t\t\tAND startdate ='" . $StartDate . "'\r\n\t\t\t\t\t\t\t\t\t\tAND enddate = '" . $EndDate . "'\r\n\t\t\t\t\t\t\t\t\t\tAND quantitybreak ='" . $QuantityBreak . "'";
                    $UpdateResult = DB_query($SQL);
                }
            }
            //end of if startdate  after NextStartDate - we have a new NextStartDate
        } else {
            $NextStartDate = ConvertSQLDate($myrow['startdate']);
        }
        $StartDate = $myrow['startdate'];
        $EndDate = $myrow['enddate'];
        $Price = $myrow['price'];
    }
    // end of loop around all prices
}
Example #30
0
         if (DateAdd(n, 1, $auction_config_data['auction_pseudo_cron_last']) < time()) {
             $bRun = TRUE;
         }
         break;
     case 'h':
         if (DateAdd(h, 1, $auction_config_data['auction_pseudo_cron_last']) < time()) {
             $bRun = TRUE;
         }
         break;
     case 'd':
         if (DateAdd(d, 1, $auction_config_data['auction_pseudo_cron_last']) < time()) {
             $bRun = TRUE;
         }
         break;
     case 'w':
         if (DateAdd(d, 7, $auction_config_data['auction_pseudo_cron_last']) < time()) {
             $bRun = TRUE;
         }
         break;
 }
 // if the last cron has been longer ago than the frequence, run the cron
 if ($bRun == TRUE) {
     // Execute cron
     include $phpbb_root_path . "auction_cron.php";
     // update last-cron-time
     $sql = "UPDATE " . AUCTION_CONFIG_TABLE . "\r\n                                 SET config_value = '" . time() . "'\r\n                                 WHERE config_name='auction_pseudo_cron_last'";
     if (!($auction_config_result = $db->sql_query($sql))) {
         message_die(GENERAL_ERROR, 'Could not update last cron time', '', __LINE__, __FILE__, $sql);
     }
     // End if
 }