condition = "PROD_ID=:prodID "; $criteria->params = array(':prodID' => $Product->ID,); $ProductBranch = StockBranch::model()->findAll($criteria); foreach ($ProductBranch as $StockQty) { $id = $StockQty->BRANCH_ID; ?>< input name='productID[]' value='ID?>' > < input name='branch[]' value='BRANCH_ID?>' > 'off', 'style' => ' width:80px; height:20px; vertical-align:top; text-align:right;', )); ?> Controllerfor ($i; $i < sizeof($_POST['branch']); $i++) { $stockQty = 0; $branch_id = $_POST['branch'][$i]; $product_id = $_POST['productID'][$i]; $stockQty = $_POST['stockQTY'][$i]; if ($stockQty == NULL) { $stockQty = 0; } else { $stockQty = $_POST['stockQTY'][$i]; } $onStock = StockBranch::model()->findByAttributes( array('BRANCH_ID' => $branch_id, 'PROD_ID' => $product_id) ); $updQty = StockBranch::model()->updateAll(array( 'STOCK_QTY'=>$onStock->STOCK_QTY + $stockQty, 'LASTUPDATE' => new CDbExpression('NOW()'), ), 'BRANCH_ID="' .$branch_id. '" AND PROD_ID="' . $product_id . '"' ); } // End Loop
yii framework php
วันพุธที่ 2 เมษายน พ.ศ. 2557
Yii Update Database From Array Data
From
Yii Database Relation | Basic
public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'TProdtype' => array(self::BELONGS_TO, 'Producttypes', array('ID' => 'PRODTYPE_ID')), 'TPrice' => array(self::BELONGS_TO, 'ProductBranch', array('ID' => 'PROD_ID')), 'TBrand' => array(self::BELONGS_TO, 'Brands', array('BRAND_ID' => 'ID')), 'TUnit' => array(self::BELONGS_TO, 'Units', array('UNIT_ID' => 'ID')), ); }
Yii View GridView | Currency (฿)
array(
'name' => 'UNIT_PRICE',
'value' => 'Yii::app()->numberFormatter->formatCurrency($data->UNIT_PRICE, "THB")',
),
array(
'name' => 'TOTAL_PRICE',
'value' => 'Yii::app()->numberFormatter->formatCurrency($data->TOTAL_PRICE, "THB")',
),
: Display ฿1234,00
Yii View | yii cgridview image size
<?php
$this->widget('bootstrap.widgets.TbGridView', array(
'type' => 'striped bordered condensed',
'itemsCssClass' => 'table table-striped table-bordered table-condensed',
'id' => 'search-grid', // id ของตาราง CGridView
'dataProvider' => $tmpOrderList, // ข้อมูล dataProvider จากภายใน Model ของ function search()
'template' => "{items}",
'columns' => array(
array(
'header' => 'No.',
'value' => '$this->grid->dataProvider->pagination->currentPage*$this->grid->dataProvider->pagination->pageSize + $row+1', // row is zero based
),
array(
'name' => 'pictures',
'type' => 'html',
'value' => '(!empty($data->PICTURES))?CHtml::image("./images/Purchase/".$data->PICTURES,"",array("style"=>"width:180px;")):"no image"',
),
'PRODUCT_CODE',
'REF_CODE',
'DESING',
'COLOR',
'SIZE_S',
'SIZE_M',
'SIZE_XL',
'SIZE_F',
'ORDER_QTY',
'UNIT_PRICE',
array(
'name' => 'UNIT_PRICE',
'value' => 'Yii::app()->numberFormatter->formatCurrency($data->UNIT_PRICE, "THB")',
),
array(
'name' => 'TOTAL_PRICE',
'value' => 'Yii::app()->numberFormatter->formatCurrency($data->TOTAL_PRICE, "THB")',
),
array(
'class' => 'bootstrap.widgets.TbButtonColumn',
'template' => ' {edit} {delete}',
'buttons' => array
(
'edit' => array
(
'label' => 'Edit',
'icon' => 'pencil white',
'url' => 'Yii::app()->createUrl("Product/AddProduct", array("prdID"=>$data->ID))',
'options' => array(
'class' => 'btn btn-small btn-success',
),
),
'delete' => array
(
'label' => 'Del',
'icon' => 'icon-trash white',
'url' => 'Yii::app()->createUrl("Product/delProduct", array("prdID"=>$data->ID))',
'options' => array(
'class' => 'btn btn-small btn-danger',
),
),
),
'htmlOptions' => array(
'style' => 'width: 80px',
),
)
),
));
?>
วันจันทร์ที่ 2 กันยายน พ.ศ. 2556
การคำนวณจำนวนวันจากการเลือกวันที่ 2 วัน StatDate - EndDate
#เลือกวันที่เริ่มต้น ในการเลือกวันที่เริ่มต้นนั้น Jquery จะทำการระบุวันที่ สิ้นสุดให้ และระบุจำนวนให้ 1 วัน และเมื่อทำการเลือกข้อมูลวันที่ สิ้นสุด ก็จะมีการคำนวณ จำนวนวันใหม่อีกครั้ง
โดยจำนวนวันจะถูกจัดเก็บใน textbox ID CarRental_rentDays
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $carRental,
'attribute' => 'begin_date',
'options' => array(
'showAnim' => 'fold',
'dateFormat' => 'dd/mm/yy',
//'minDate' => '0',
'minDate' => 'new Date()',
'changeYear' => 'true', // แสดง Dropdown เลือกปี
'changeMonth' => 'true', // แสดง Dropdown เลือกเดือน
'onSelect' => 'js:function( selectedDate ) {
$( "#' . CHtml::activeId($carRental, 'end_date') . '" ).datepicker("option", "minDate", selectedDate); //set the end date cjuidatepiker minDate and its working fine
$("#CarRental_end_date").val(selectedDate);
var startDate = $("#CarRental_begin_date").val().split("/");
var begin_date = new Date(startDate[2], startDate[1] - 1, startDate[0]);
var endDate = $("#CarRental_end_date").val().split("/");
var end_date = new Date(endDate[2], endDate[1] - 1, endDate[0]);
var days = (end_date - begin_date) / (1000*60*60*24);
$("#CarRental_rentDays").val(days+1);
}',
),
'htmlOptions' => array(
'style' => 'width:105px;vertical-align:top;font-size:0.9em;'
),
));
?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$carRental,
// 'value' =>($carRental->end_date)?$carRental->begin_date:date('d/m/Y', strtotime("+1 day")),
'attribute'=>'end_date',
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'dd/mm/yy',
'changeYear' => 'true', // แสดง Dropdown เลือกปี
'changeMonth' => 'true', // แสดง Dropdown เลือกเดือน
'onSelect'=> 'js:function(selectedDate) {
$("#CarRental_end_date").val(selectedDate); // Why do you need this?
var startDate = $("#CarRental_begin_date").val().split("/");
var endDate = $("#CarRental_end_date").val().split("/");
var begin_date = new Date(startDate[2], startDate[1] - 1, startDate[0]);
var end_date = new Date(endDate[2], endDate[1] - 1, endDate[0]);
var days = (end_date - begin_date) / (1000*60*60*24);
$("#CarRental_rentDays").val(days+1);
}',
),
'htmlOptions'=>array(
'style'=>'width:105px;vertical-align:top;font-size:0.9em;'
),
)); ?>
โดยจำนวนวันจะถูกจัดเก็บใน textbox ID CarRental_rentDays
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model' => $carRental,
'attribute' => 'begin_date',
'options' => array(
'showAnim' => 'fold',
'dateFormat' => 'dd/mm/yy',
//'minDate' => '0',
'minDate' => 'new Date()',
'changeYear' => 'true', // แสดง Dropdown เลือกปี
'changeMonth' => 'true', // แสดง Dropdown เลือกเดือน
'onSelect' => 'js:function( selectedDate ) {
$( "#' . CHtml::activeId($carRental, 'end_date') . '" ).datepicker("option", "minDate", selectedDate); //set the end date cjuidatepiker minDate and its working fine
$("#CarRental_end_date").val(selectedDate);
var startDate = $("#CarRental_begin_date").val().split("/");
var begin_date = new Date(startDate[2], startDate[1] - 1, startDate[0]);
var endDate = $("#CarRental_end_date").val().split("/");
var end_date = new Date(endDate[2], endDate[1] - 1, endDate[0]);
var days = (end_date - begin_date) / (1000*60*60*24);
$("#CarRental_rentDays").val(days+1);
}',
),
'htmlOptions' => array(
'style' => 'width:105px;vertical-align:top;font-size:0.9em;'
),
));
?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$carRental,
// 'value' =>($carRental->end_date)?$carRental->begin_date:date('d/m/Y', strtotime("+1 day")),
'attribute'=>'end_date',
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'dd/mm/yy',
'changeYear' => 'true', // แสดง Dropdown เลือกปี
'changeMonth' => 'true', // แสดง Dropdown เลือกเดือน
'onSelect'=> 'js:function(selectedDate) {
$("#CarRental_end_date").val(selectedDate); // Why do you need this?
var startDate = $("#CarRental_begin_date").val().split("/");
var endDate = $("#CarRental_end_date").val().split("/");
var begin_date = new Date(startDate[2], startDate[1] - 1, startDate[0]);
var end_date = new Date(endDate[2], endDate[1] - 1, endDate[0]);
var days = (end_date - begin_date) / (1000*60*60*24);
$("#CarRental_rentDays").val(days+1);
}',
),
'htmlOptions'=>array(
'style'=>'width:105px;vertical-align:top;font-size:0.9em;'
),
)); ?>
วันจันทร์ที่ 1 กรกฎาคม พ.ศ. 2556
Query Data Replace On AR Yii createCommand
#Query Data Replace
$connection = yii::app()->db;
$sql = "replace into tborder_details(
OrderNo,
ProductID,
Qty,
Price,
TotalPrice,
OrderDate
)
select
'".$NewOrderNo."',
ctmp.ProductID,
Qty,
IF(promotion = 'Y',price_promotion,price_cash) AS Price,
IF(promotion = 'Y',price_promotion*Qty,price_cash*Qty) AS TotalPrice,
OrderDate
From cart ctmp
inner join tbproducts prd ON (prd.ProductID = ctmp.ProductID)
where SessionOrder = '" . $SessionID . "' and OrderDate = '" . date('Y-m-d') . "' and OrderIP ='" . $IPadd . "'
";
$command = $connection->createCommand($sql);
$command->execute();
//ลบข้อมูลออกจากระบบ
$connection = yii::app()->db;
$sql1 = " delete from cart where SessionOrder = '" . $SessionID . "' and OrderDate = '" . date('Y-m-d') . "' and OrderIP ='" . $IPadd . "' ";
$command = $connection->createCommand($sql1);
$command->execute();
$connection = yii::app()->db;
$sql = "replace into tborder_details(
OrderNo,
ProductID,
Qty,
Price,
TotalPrice,
OrderDate
)
select
'".$NewOrderNo."',
ctmp.ProductID,
Qty,
IF(promotion = 'Y',price_promotion,price_cash) AS Price,
IF(promotion = 'Y',price_promotion*Qty,price_cash*Qty) AS TotalPrice,
OrderDate
From cart ctmp
inner join tbproducts prd ON (prd.ProductID = ctmp.ProductID)
where SessionOrder = '" . $SessionID . "' and OrderDate = '" . date('Y-m-d') . "' and OrderIP ='" . $IPadd . "'
";
$command = $connection->createCommand($sql);
$command->execute();
//ลบข้อมูลออกจากระบบ
$connection = yii::app()->db;
$sql1 = " delete from cart where SessionOrder = '" . $SessionID . "' and OrderDate = '" . date('Y-m-d') . "' and OrderIP ='" . $IPadd . "' ";
$command = $connection->createCommand($sql1);
$command->execute();
วันพฤหัสบดีที่ 27 มิถุนายน พ.ศ. 2556
Yii Shoping Cart2
public function actionAddToCart($ProductID) {
$SessionID = Yii::app()->session->sessionID;
$IPadd = Yii::app()->request->userHostAddress;
$Cart = New Cart();
$ProductID = $_GET['ProductID'];
$Cart->ProductID = $ProductID;
$Cart->SessionOrder = $SessionID;
$Cart->OrderIP = $IPadd;
$Cart->OrderDate = date('Y-m-d H:i:s');
$chkOrderList = Yii::app()->db->createCommand()
->select()
->from('cart')
->where('ProductID = :ProductID and SessionOrder = :SessionID', array(':ProductID' => $_GET['ProductID'], ':SessionID' => $SessionID))
->queryScalar();
if(!empty($_GET['ProductID'])){
//Loop ตราจสอบข้อมูลการสั่งซื้อ
if($_GET['ProductID'] = $chkOrderList['ProductID'] and $SessionID = $chkOrderList['SessionOrder'] ){
// Update ข้อมูลกรณีที่มีการสั่งซื้อสินค้า รหัสนี้แล้วจาก Session เดียวกัน
$Cart = Cart::model()->findBypk(array('ProductID' => $ProductID, 'SessionOrder' => $SessionID));
}
$Cart->Qty = $Cart->Qty + 1;
if($Cart->save()){
$this->redirect(array("site/OrderList"));
}
}
}
$SessionID = Yii::app()->session->sessionID;
$IPadd = Yii::app()->request->userHostAddress;
$Cart = New Cart();
$ProductID = $_GET['ProductID'];
$Cart->ProductID = $ProductID;
$Cart->SessionOrder = $SessionID;
$Cart->OrderIP = $IPadd;
$Cart->OrderDate = date('Y-m-d H:i:s');
$chkOrderList = Yii::app()->db->createCommand()
->select()
->from('cart')
->where('ProductID = :ProductID and SessionOrder = :SessionID', array(':ProductID' => $_GET['ProductID'], ':SessionID' => $SessionID))
->queryScalar();
if(!empty($_GET['ProductID'])){
//Loop ตราจสอบข้อมูลการสั่งซื้อ
if($_GET['ProductID'] = $chkOrderList['ProductID'] and $SessionID = $chkOrderList['SessionOrder'] ){
// Update ข้อมูลกรณีที่มีการสั่งซื้อสินค้า รหัสนี้แล้วจาก Session เดียวกัน
$Cart = Cart::model()->findBypk(array('ProductID' => $ProductID, 'SessionOrder' => $SessionID));
}
$Cart->Qty = $Cart->Qty + 1;
if($Cart->save()){
$this->redirect(array("site/OrderList"));
}
}
}
สมัครสมาชิก:
บทความ (Atom)