how to set excel cell to 2 decimal places using phpexcel - phpexcel

while ($input = $data_query->fetch(PDO::FETCH_ASSOC))
{
$row++;
$letter2 = "A";
$row++;
$letter2 = "A";
$objPHPExcel->getActiveSheet()->SetCellValue($letter2++.$row, $input['emp_loan_code']);
$objPHPExcel->getActiveSheet()->SetCellValue($letter2++.$row, $input['date_from']);
$objPHPExcel->getActiveSheet()->SetCellValue($letter2++.$row, $input['date_to']);
if ($input['status'] == 0) {
$input['status'] = 'Pending';
$objPHPExcel->getActiveSheet()->SetCellValue($letter2++.$row, $input['status']);
}
elseif ($input['status'] == 1) {
$input['status'] = 'Paid';
$objPHPExcel->getActiveSheet()->SetCellValue($letter2++.$row, $input['status']);
}
elseif ($input['status'] == 2) {
$input['status'] = 'Cancel';
$objPHPExcel->getActiveSheet()->SetCellValue($letter2++.$row, $input['status']);
}
else{
$input['status'] = 'Request';
$objPHPExcel->getActiveSheet()->SetCellValue($letter2++.$row, $input['status']);
}
$objPHPExcel->getActiveSheet()->SetCellValue($letter2.$row, $input['amount'])->getStyle()->getNumberFormat()->setFormatCode('0.00');
}
i want to set the entire E column to be 2 decimal places and
i already set it to 2 decimal buy the output is still 00.00000
how can i display the output 00.00
thanks

Instead of using this:
$objPHPExcel->getActiveSheet()->SetCellValue($letter2.$row, $input['amount'])->getStyle()->getNumberFormat()->setFormatCode('0.00');
Try this:
$objPHPExcel->getActiveSheet()->SetCellValue($letter2.$row, number_format($input['amount'],2,'.',''));

Related

How to populate data related to an item from the location which is same for all items in Xamarin.forms

I am developing an xamarin.forms app ,I have various fields like Item Name ,Item Number and location ,here Location of all the items are same ,by entering names or number of the items the values are generated automatically because name and number are unique but since the location number is common is for all the items I am not able to populate correct data related to a particular field ,I am using sqlite database in my project can anyone please suggest me on what basis can I generate related values ?
Here is the code
public async void OnSearch_Location(object o, EventArgs args)
{
if (location.Text == string.Empty || location.Text == null)
{
await Navigation.PushAsync(new ListValuePage("Location", filePath,
pos, list));
}
else
{
for (int p = 0; p < list.Count; p++)
{
if (list.ElementAt(p).Aisle + "." + list.ElementAt(p).Bin +
"." + list.ElementAt(p).Level == location.Text)
{
line.Text =
Convert.ToString(list.ElementAt(p).Line_Number);
location.Text = list.ElementAt(p).Aisle + "." +
list.ElementAt(p).Bin + "." + list.ElementAt(p).Level;
item.Text = list.ElementAt(p).Item_Number;
name.Text = list.ElementAt(p).Name;
if (list.ElementAt(p).Order_Qty == 0)
{
order_uom.Text = "";
}
else
{
order_qty.Text =
Convert.ToString(list.ElementAt(p).Order_Qty);
}
order_uom.Text = list.ElementAt(p).Order_UOM;
if (list.ElementAt(p).Consumption_UOM == string.Empty ||
list.ElementAt(p).Consumption_UOM == null)
{
consume_lbl.IsVisible = false;
consume_qty.IsVisible = false;
consume_uom.IsVisible = false;
}
else
{
consume_lbl.IsVisible = true;
consume_qty.IsVisible = true;
consume_uom.IsVisible = true;
if (list.ElementAt(p).Consumption_Qty == 0)
{
consume_qty.Text = "";
}
else
{
consume_qty.Text =
Convert.ToString(list.ElementAt(p).Consumption_Qty);
}
consume_uom.Text = list.ElementAt(p).Consumption_UOM;
}
}
}
}
}

How to create Query using IN?

I need to collect data and add it to temporary table in AX 2012 R3 using X++.
This is the Query on SQL
select store, receiptid, itemid, str(qty,16,0) as Qty, str(price,16,0) as Price, str(DISCAMOUNT,16,0) DiscAmount, str(taxamount,16,0) SalesTaxAmount ,convert(date, transdate) transdate, DATAAREAID from RETAILTRANSACTIONSALESTRANS
where DATAAREAID in ('5740','5760') and transdate >='2016-03-21' and transdate <='2016-03-27' and store in ('JTJDRN1','JNUSADP','JOFFICE')
and INVENTSTATUSSALES='2' and itemid in ('10010038') and receiptid in (select receiptid from RETAILTRANSACTIONPAYMENTTRANS where transdate >='2016-03-21' and transdate <='2016-03-27')
order by transdate
User can input transDate, itemid and storeid
this is what form looks like
this is my code so far
private void RetailPromoReport()
{
str receiptId, curDatetxt,fileLocation, filePath, itemtxt, startPtxt, endPtxt,
storetxt, item_txt, item2, receiptId2, rcptid_txt, store_txt, store2;
FileName fileName;
str 50 item, itemid, store;
container items, receiptid_con, stores;
int i,x, ware, itm, tot, y,z, rcptLen, storeLen;
Date emptyDate, startP, endP;
RetailTransactionPaymentTrans rtpt;
RetailTransactionSalesTrans rtst;
ReportRetailTemp rrpi_tmp, rrpi_tmp2;
QueryBuildRange qbr1, qbr2, qbr3, qbr4, qbr5;
QueryRun queryRun;
Query query, query2;
QueryBuildDataSource qbdsRetailTransactionPaymentTrans, qbdsRetailTransactionSalesTrans;
RecordInsertList recordILCRppi_tmp = new RecordInsertList(tableNum(ReportRetailTemp),false,false,false,false,false,rrpi_tmp);
;
startP = DateFrom.dateValue();
endP = DateTo.dateValue();
tot = 0;
delete_from rrpi_tmp;
while select receiptId from rtpt group by rtpt.receiptId where rtpt.transDate >= startP && rtpt.transDate <= endP
{
receiptid_con += rtpt.receiptId;
}
query = new Query();
qbdsRetailTransactionSalesTrans = query.addDataSource(tableNum(RetailTransactionSalesTrans));
qbr1 = qbdsRetailTransactionSalesTrans.addRange(fieldNum(RetailTransactionSalesTrans,TransDate));
qbr1.value(strfmt('(%3.transDate>=%1) && (%3.transDate<=%2)',Date2StrXpp(startP),Date2StrXpp(endP),qbdsRetailTransactionSalesTrans.name()));
qbr2 = qbdsRetailTransactionSalesTrans.addRange(fieldNum(RetailTransactionSalesTrans,inventStatusSales));
qbr2.value(queryValue(enum2str(RetailInventStatusSales::Posted)));
items = msCtrlCust.getSelectedFieldValues();
itemtxt = multilookupItem.valueStr();
stores = msCtrlStore.getSelectedFieldValues();
storetxt = multilookupStore.valueStr();
if(itemtxt != "")
{
item_txt = conPeek(items,1);
item2 = strFmt('(%2.itemId == "%1") ',queryValue(conPeek(items,1)),qbdsRetailTransactionSalesTrans.name());
itm = conlen(items);
if(itm > 1)
{
for (i = 2; i <= itm;i++)
{
item = conPeek(items,i);
item2 = strFmt('%1 || (%3.itemId == "%2") ',item2, queryValue(item),qbdsRetailTransactionSalesTrans.name());
}
}
qbr3 = qbdsRetailTransactionSalesTrans.addRange(fieldNum(RetailTransactionSalesTrans, itemId));
qbr3.value(strFmt("%1",item2));
}
rcptLen = conlen(receiptid_con);
receiptId2 = strFmt('(%2.receiptId == "%1") ',queryValue(conPeek(receiptid_con,1)),qbdsRetailTransactionSalesTrans.name());
if(rcptLen > 1)
{
for (y = 2; y <= rcptLen; y++)
{
rcptid_txt = conPeek(receiptid_con,y);
receiptId2 = strFmt('%1 || (%3.receiptId == "%2") ',receiptId2, queryValue(rcptid_txt),qbdsRetailTransactionSalesTrans.name());
}
}
qbr4 = qbdsRetailTransactionSalesTrans.addRange(fieldNum(RetailTransactionSalesTrans, receiptId));
qbr4.value(strFmt("%1",receiptId2));
if(storetxt != '')
{
store_txt = conPeek(stores,1);
store2 = strFmt('(%2.store == "%1") ',queryValue(conPeek(stores,1)),qbdsRetailTransactionSalesTrans.name());
storeLen = conlen(stores);
if(storeLen > 1)
{
for (z = 2; z <= storeLen;z++)
{
store = conPeek(stores,z);
store2 = strFmt('%1 || (%3.store == "%2") ',store2, queryValue(store),qbdsRetailTransactionSalesTrans.name());
}
}
qbr5 = qbdsRetailTransactionSalesTrans.addRange(fieldNum(RetailTransactionSalesTrans, store));
qbr5.value(strFmt("%1",store2));
}
qbdsRetailTransactionSalesTrans.addSortField(fieldNum(RetailTransactionSalesTrans, transDate),SortOrder::Ascending);
qbdsRetailTransactionSalesTrans.addSortField(fieldNum(RetailTransactionSalesTrans, itemId),SortOrder::Ascending);
queryRun = new QueryRun(query);
while (queryRun.next())
{
rtst = queryRun.getNo(1);
rrpi_tmp.store = rtst.store;
rrpi_tmp.receiptId = rtst.receiptId;
rrpi_tmp.itemId = rtst.itemId;
rrpi_tmp.qty = rtst.qty;
rrpi_tmp.price = rtst.price;
rrpi_tmp.discAmount = rtst.discAmount;
rrpi_tmp.SalestaxAmount = rtst.taxAmount;
rrpi_tmp.transDate = rtst.transDate;
recordILCRppi_tmp.add(rrpi_tmp);
tot++;
}
ttsBegin;
recordILCRppi_tmp.insertDatabase();
ttsCommit;
ReportRetailTemp_ds.research(true);
ReportRetailTemp_ds.refresh();
if(tot > 0)
{
Box::info(strFmt("%1 row data",tot));
}
else
{
Box::info(strFmt("No Data",tot));
}
}
My code doesn't show any error in short period but because receiptId is stored in str,
receiptId2 = strFmt('%1 || (%3.receiptId == "%2") ',receiptId2, queryValue(rcptid_txt),qbdsRetailTransactionSalesTrans.name());
there is limitation and show error for long periode
Can someone make my code more efficient and
is there any way to create Query in x++ that have same function like "IN" on SQL
You have two options:
You can use more than one query range for the same field; it will automatically count as an or
for (i = conLen(items); i > 0; i--)
qbdsRetailTransactionSalesTrans.addRange(fieldNum(RetailTransactionSalesTrans, itemId)).value(queryValue(conPeek(items,i)));
You may need special handling, if the container is empty!
Often it is better to use an (exists) join instead
ds = qbdsRetailTransactionSalesTrans.addDatasource(tableNum(RetailTransactionPaymentTrans));
ds.joinMode(JoinMode::ExistsJoin);
ds.relations(true); // Or do ds.addLink(...) etc.
I am not sure I follow the correct logic here :)
If you need to do crosscompany selections, do so using the interface for that:
qbdsRetailTransactionSalesTrans.allowCrossCompany(true);
qbdsRetailTransactionSalesTrans.addCompanyRange('5740');
qbdsRetailTransactionSalesTrans.addCompanyRange('5760');

data on repeater takes too long to load

I have a page that runs reports on sales for a time period. When I run it for a month with around 88 transactions, its take a while but I can live with it for now.
Problem is when I try run the page for a year or over 3 months, its takes around 30minutes then goes to an error page saying "The cms.kics.com.au isnt working.. It didnt send any data...err_empty_response".
]
First thing comes to mind is there is too much data to return and its timing out on the request.
I have increased the execution time in the web.config and also the page timeout but no luck.
<httpRuntime maxRequestLength="409600" executionTimeout="720" />
Page.Server.ScriptTimeout = 3600;
I also tried flushing the data each time it goes in the repeater but doesn't do anything.
The code behide calculates the totals for the data range works fine but when it populates the salesrepeater with all the products that was sold, I get a timeout.
Is there a way to resolve this?
I was thinking maybe a stored procedure to run in the background that calculates the total for all products and on the repeater, just to output each item.
sales by 3 months can go up to 300-400.
Please see below code.
protected void BtnFilter_Click(object sender, EventArgs e)
{
if (StartDate.SelectedDate == null && FinishDate.SelectedDate == null)
return;
startDate = DateTime.Parse(StartDate.SelectedDate.ToString()).Date;
endDate = DateTime.Parse(FinishDate.SelectedDate.ToString()).Date;
DateTime now = DAL.TimeZoneConversion.ConvertDateTime(DateTime.UtcNow, thisShop.Company.TimeZoneLocationID);
CurrentDateTimeLiteral.Text = now.ToString() + " (" + thisShop.Company.TimeZoneLocationID + ")";
DateRangeLiteral.Text = startDate.ToShortDateString() + " - " + endDate.ToShortDateString();
TaxTypeLiteral.Text = thisShop.TaxName;
TaxTypeLiteral2.Text = thisShop.TaxName;
TaxTypeLiteral3.Text = thisShop.TaxName;
TaxTypeLiteral4.Text = thisShop.TaxName;
TaxTypeLiteral5.Text = thisShop.TaxName;
TaxTypeLiteral6.Text = thisShop.TaxName;
TaxTypeLiteral7.Text = thisShop.TaxName;
TaxTypeLiteral8.Text = thisShop.TaxName;
TaxTypeLiteral9.Text = thisShop.TaxName;
IObjectScope scope = ORM.ScopeFactory.GetPerRequestScope(HttpContext.Current);
decimal totalPAmount = 0;
decimal totalPTax = 0;
decimal totalDAmount = 0;
decimal totalDTax = 0;
decimal totalAmount = 0;
decimal totalTax = 0;
var shopOrders = (from shopOrder in scope.Extent<ORM.Shoporder>()
where shopOrder.ShopId == shopId &&
shopOrder.CreateDateTime.Date >= startDate && shopOrder.CreateDateTime.Date <= endDate && shopOrder.IsDeleted == false &&
(shopOrder.IsReceiptSent == true || shopOrder.IsReceiptSkipped == true)
orderby shopOrder.CreateDateTime descending
select shopOrder);
foreach (ORM.Shoporder thisShopOrder in shopOrders.ToList())
{
decimal orderTotal = thisShopOrder.TotalCostIncludingTax; //DAL.DataClasses.ShopOrder.CalculateOrderTotal(thisShopOrder.ShopOrderId);
totalAmount += thisShopOrder.TotalCostIncludingTax;
totalTax += thisShopOrder.TotalTaxCost;
totalPAmount += thisShopOrder.ProductCostIncludingTax;
totalPTax += thisShopOrder.ProductTaxCost;
totalDAmount += thisShopOrder.DeliveryCostIncludingTax;
totalDTax += thisShopOrder.DeliveryTaxCost;
}
TotalLiteral.Text = totalAmount.ToString("C");
TotalTaxLiteral.Text = totalTax.ToString("C");
TotalDLiteral.Text = totalDAmount.ToString("C");
TotalDTaxLiteral.Text = totalDTax.ToString("C");
TotalPLiteral.Text = totalPAmount.ToString("C");
TotalPTaxLiteral.Text = totalPTax.ToString("C");
ReportDiv.Visible = true;
Populate();
}
private void Populate()
{
IObjectScope scope = ORM.ScopeFactory.GetPerRequestScope(HttpContext.Current);
var result = from o in scope.Extent<ORM.Shopproductvariationprice>()
where o.Shopproduct.Shopcategory.ShopId == shopId
orderby o.Name, o.PriceIncludingTax
select o;
SaleRepeater.DataSource = result.ToList();
SaleRepeater.DataBind();
}
protected void SaleRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
IObjectScope scope = ORM.ScopeFactory.GetPerRequestScope(HttpContext.Current);
RepeaterItem item = e.Item;
if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
{
ORM.Shopproductvariationprice thisPrice = (ORM.Shopproductvariationprice)item.DataItem;
Literal ProductNameLiteral = (Literal)item.FindControl("ProductNameLiteral");
Literal ProductCountLiteral = (Literal)item.FindControl("ProductCountLiteral");
Literal ProductAmountIncludingTaxLiteral = (Literal)item.FindControl("ProductAmountIncludingTaxLiteral");
Literal ProductAmountExcludingTaxLiteral = (Literal)item.FindControl("ProductAmountExcludingTaxLiteral");
Literal ProductTaxLiteral = (Literal)item.FindControl("ProductTaxLiteral");
int productCount = 0;
decimal productAmount = 0;
decimal productTax = 0;
ProductNameLiteral.Text = thisPrice.Name;
var shopOrders = (from shopOrder in scope.Extent<ORM.Shoporder>()
where shopOrder.ShopId == shopId &&
shopOrder.CreateDateTime.Date >= startDate && shopOrder.CreateDateTime.Date <= endDate && shopOrder.IsDeleted == false &&
(shopOrder.IsReceiptSent == true || shopOrder.IsReceiptSkipped == true)
orderby shopOrder.CreateDateTime descending
select shopOrder);
foreach (ORM.Shoporder thisShopOrder in shopOrders.ToList())
{
foreach (ORM.Shoporderproduct thisShopOrderProduct in DAL.DataClasses.ShopOrder.GetProductsInOrder(thisShopOrder.ShopOrderId))
{
if (thisShopOrderProduct.ShopProductVariationPriceId == thisPrice.ShopProductVariationPriceId)
{
productCount += thisShopOrderProduct.Quantity;
productAmount += (thisShopOrderProduct.Quantity * thisShopOrderProduct.Shopproductvariationprice.PriceIncludingTax);
if (thisShopOrderProduct.Shopproductvariationprice.Shopproduct.IsTaxable)
{
decimal taxRate = 100 + thisShop.TaxPercent;
decimal thisProductPriceExcludingTax = thisShopOrderProduct.Shopproductvariationprice.PriceIncludingTax * 100;
thisProductPriceExcludingTax = thisProductPriceExcludingTax / taxRate;
decimal thisProductTax = thisShopOrderProduct.Shopproductvariationprice.PriceIncludingTax - thisProductPriceExcludingTax;
productTax += (thisShopOrderProduct.Quantity * thisProductTax);
}
}
}
}
ProductCountLiteral.Text = productCount.ToString();
ProductAmountIncludingTaxLiteral.Text = productAmount.ToString("C");
ProductAmountExcludingTaxLiteral.Text = (productAmount - productTax).ToString("C");
ProductTaxLiteral.Text = productTax.ToString("C");
totalProductAmount += productAmount;
totalProductTax += productTax;
totalItemsSold += productCount;
Response.Flush();
}
if (item.ItemType == ListItemType.Footer)
{
Literal TotalCountLiteral = (Literal)item.FindControl("TotalCountLiteral");
Literal TotalAmountIncludingTaxLiteral = (Literal)item.FindControl("TotalAmountIncludingTaxLiteral");
Literal TotalAmountExcludingTaxLiteral = (Literal)item.FindControl("TotalAmountExcludingTaxLiteral");
Literal TotalTaxLiteral = (Literal)item.FindControl("TotalTaxLiteral");
TotalCountLiteral.Text = totalItemsSold.ToString();
TotalAmountIncludingTaxLiteral.Text = totalProductAmount.ToString("C");
TotalAmountExcludingTaxLiteral.Text = (totalProductAmount - totalProductTax).ToString("C");
TotalTaxLiteral.Text = totalProductTax.ToString("C");
}
}
}

javafx checklistree output: the term inter comma

for (CheckBoxTreeItem<String> treeItem : treeItems) {
if (treeItem.isSelected()) {
if (treeItem.getValue() != null) {
konular = konular + treeItem.getValue();
}
}
}
System.out.println(konular);
hi, this code for checktreeviews ,treelist sample1 sample2...
I have any choice, output: nullSample3Sample4
I want: sample3, sample4
The Java 8 way:
String konular = treeItems
.stream()
.map(TreeItem::getValue)
.filter(value -> value != null)
.collect(Collectors.joining(", "));
Try setting your variable like this:
String konular = "";
I believe it is currently turning null into a string when you add the first new string, and thus you end up with it starting with "null".
To add the comma, you could do something like this:
for (CheckBoxTreeItem<String> treeItem : treeItems) {
if (treeItem.isSelected()) {
if (treeItem.getValue() != null) {
if(konular!=""){
konular = konular + ", ";
}
konular = konular + treeItem.getValue();
}
}
}
I'm sure it's not the cleanest way, but it should do the trick.

shift select records in gridview asp.net

hey guys,
i have a gridview which displays 10records per page, now i want to implement shift+click option in my gridview, when user clicks on the first row and press shift key and click on the 5th row, all the rows between 1 and 5(1 and 5 inclusive) should be selected...
can anyone suggest how should i do this in javascript.
I take it back, I found a shift+click multiple select solution for a gridview. All credit goes to mdv over at the asp forums.
var _sPreviousRow = null;
function wsCheckRange(p_oGridView, p_oControl, e) {
var l_sCheckID = p_oControl.id;
var l_aCheckIDParts = l_sCheckID.split(p_oGridView.id);
var l_sCurrentRow = l_aCheckIDParts[1].split('_')[1].substring(3);
var l_oEvent = (window.event) ? event : e;
if (l_oEvent.shiftKey) {
if (_sPreviousRow != null && _sPreviousRow != l_sCurrentRow) {
var l_iFirst = 0, l_iLast = 0;
if (parseInt(_sPreviousRow,10) > parseInt(l_sCurrentRow,10)) {
l_iFirst = parseInt(l_sCurrentRow,10);
l_iLast = parseInt(_sPreviousRow,10);
}
else {
l_iFirst = parseInt(_sPreviousRow,10);
l_iLast = parseInt(l_sCurrentRow,10);
}
for (var i = l_iFirst; i < l_iLast; i++) {
var l_sLastRow = (i <= 9 ? '0' + i : i);
var l_sCtrlNew = l_sCheckID.replace('ctl' + l_sCurrentRow, 'ctl' + l_sLastRow);
var l_oCtrlNew = $get(l_sCtrlNew);
if (l_oCtrlNew) {
l_oCtrlNew.checked = p_oControl.checked;
}
}
}
_sPreviousRow = null;
}
else {
_sPreviousRow = l_sCurrentRow;
}
}

Resources