import { ProductEntity } from 'ionic-np-core-entitycomponent/src' import { ProductDiscountEntity } from 'ionic-np-core-entitycomponent/src' import { ProductMRPEntity } from 'ionic-np-core-entitycomponent/src' import { ProductPriceEntity } from 'ionic-np-core-entitycomponent/src' import { ProductTaxEntity } from 'ionic-np-core-entitycomponent/src' import { ProductDiscountBC } from '../../businesscomponent/product/productdiscountbc' import { ProductTaxBC } from '../../businesscomponent/product/producttaxbc' import { ProductPriceBC } from '../../businesscomponent/product/productpricebc' import { ProductMRPBC } from '../../businesscomponent/product/productmrpbc' import { FileUtility } from '../../businesscomponent/common/fileutility' import { DBProvider } from 'ionic-np-dbprovider/src' import { ServiceProvider } from 'ionic-np-serviceprovider/src' import { Transfer, FileUploadOptions, TransferObject } from '@ionic-native/transfer' import { File } from '@ionic-native/file'; import { Injectable } from '@angular/core'; @Injectable() export class ProductBC { constructor(private serviceprovider: ServiceProvider) { } public Read(): Promise { return new Promise(function (resolve, reject) { let dbProvider: DBProvider; let productEntity: ProductEntity[]; dbProvider = new DBProvider(); let retValue: Array; dbProvider.Read(ProductEntity.TABLE_NAME) .then((resultSet) => { if (resultSet.rows.length > 0) { productEntity = new Array(resultSet.rows.length); for (let i = 0; i < resultSet.rows.length; i++) { productEntity[i] = new ProductEntity(); productEntity[i].PRD_CD = resultSet.rows.item(i).PRD_CD; productEntity[i].PRD_DESC = resultSet.rows.item(i).PRD_DESC; productEntity[i].PRD_IMG = resultSet.rows.item(i).PRD_IMG; } } resolve(productEntity); }); }); } public ReadProductDiscount(productEntity: Array): Promise { return new Promise(function (resolve, reject) { let count: number; count = 0; productEntity.map(function (item) { let productDiscountBC = new ProductDiscountBC(null); productDiscountBC.Read( "where PRD_CD='" + item.PRD_CD + "'") .then((result: Array) => { count = count + 1; item.M_PRDDISC = result as ProductDiscountEntity[]; if (count == productEntity.length) resolve(productEntity); }); }); }); } public ReadProductTax(productEntity: Array): Promise { return new Promise(function (resolve, reject) { let count: number; count = 0; productEntity.map(function (item) { let productTaxBC = new ProductTaxBC(null); productTaxBC.Read("where PRD_CD='" + item.PRD_CD + "'") .then((result: Array) => { count = count + 1; item.M_PRDTAX = result as ProductTaxEntity[]; if (count == productEntity.length) resolve(productEntity); }); }); }); } public ReadProductPrice(productEntity: Array): Promise { return new Promise(function (resolve, reject) { let count: number; count = 0; productEntity.map(function (item) { let productPriceBC = new ProductPriceBC(null); productPriceBC.Read( "where PRD_CD='" + item.PRD_CD + "'") .then((result: Array) => { count = count + 1; item.M_PRDPRC = result as ProductPriceEntity[]; if (count == productEntity.length) resolve(productEntity); }); }); }); } public ReadProductMRP(productEntity: Array): Promise { return new Promise(function (resolve, reject) { let count: number; count = 0; productEntity.map(function (item) { let productMRPBC = new ProductMRPBC(null); productMRPBC.Read( "where PRD_CD='" + item.PRD_CD + "'") .then((result: Array) => { count = count + 1; item.M_PRDMRP = result as ProductMRPEntity[]; if (count == productEntity.length) resolve(productEntity); }); }); }); } public Create(productEntity: Array): Promise { return new Promise(function (resolve, reject) { let dbProvider: DBProvider; dbProvider = new DBProvider(); let strSqls: Array; strSqls = new Array(); for (let i = 0; i < productEntity.length; i++) { strSqls.push("insert into " + ProductEntity.TABLE_NAME + " (PRD_CD,PRD_DESC,PRD_IMG) VALUES ('" + productEntity[i].PRD_CD + "','" + productEntity[i].PRD_DESC + "','" + productEntity[i].PRD_IMG + "')" ); } dbProvider.ExecuteSql(strSqls) .then(() => { resolve(productEntity); }) .catch((e) => { reject (e); }); }); } public Get(httpUrl: string): Promise { return new Promise(resolve => { this.serviceprovider.Get(httpUrl).subscribe((result) => { let productentity: Array; productentity = new Array(); for (let i = 0; i < result.length; i++) { let product: ProductEntity; product = new ProductEntity(); product.PRD_CD = result[i].PRD_CD; product.PRD_DESC = result[i].PRD_DESC; product.PRD_IMG = result[i].PRD_IMG; productentity.push(product); } resolve(productentity); }); }); } public GetImage(httpurl: string,productEntity: Array) { let fileutility: FileUtility; fileutility = new FileUtility(new Transfer(), new File()); for (let i = 0; i < productEntity.length; i++) { //fileutility.Download(productEntity[i].PRD_IMG, productEntity[i].PRD_CD); fileutility.Download(httpurl + "\\" + productEntity[i].PRD_CD.substring(7), productEntity[i].PRD_CD + ".jpg"); } fileutility.Download(httpurl, "PRDCODEDEFAULT.jpg"); } }