UtilsController.cs 153 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097
  1. using System;
  2. using System.Collections.Generic;
  3. //using System.Drawing;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml.Linq;
  8. using Aspose.Words;
  9. using Aspose.Words.Saving;
  10. using DocumentFormat.OpenXml.Packaging;
  11. using Microsoft.AspNetCore.Mvc;
  12. using Spire.Doc;
  13. using SuperCms.Models;
  14. using Syncfusion.DocIO;
  15. using Syncfusion.DocIO.DLS;
  16. using Syncfusion.Drawing;
  17. using OutlineLevel = Syncfusion.DocIO.OutlineLevel;
  18. using System.IO;
  19. using System.Globalization;
  20. using Syncfusion.XlsIO;
  21. using System.Net.Http;
  22. using System.Net;
  23. using System.Text.RegularExpressions;
  24. namespace SuperCms.Controllers
  25. {
  26. public class UtilsController
  27. {
  28. private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
  29. public static string[] validformats = new[] {
  30. "MM/dd/yyyy",
  31. "yyyy/MM/dd",
  32. "dd/MM/yyyy HH:mm:ss",
  33. "MM/dd/yyyy HH:mm:ss",
  34. "MM/dd/yyyy hh:mm tt",
  35. "yyyy-MM-dd HH:mm:ss, fff",
  36. "yyyy-MM-ddTHH:mm:ss",
  37. "yyyy-MM-ddTHH:mm",
  38. "yyyy-MM-ddTHH:mm:ss.fff",
  39. "yyyy-MM-dd",
  40. "HH:mm:ss","HH:mm"};
  41. public static String convertLargeNumberToString(int remain, String resString)
  42. {
  43. int result, phanDu;
  44. if (remain > 1000)
  45. {
  46. result = remain / 1000;
  47. phanDu = remain - result * 1000;
  48. if (resString == "")
  49. {
  50. return convertLargeNumberToString(phanDu, resString + "." + phanDu);
  51. }
  52. return convertLargeNumberToString(phanDu, resString + ".");
  53. }
  54. else
  55. {
  56. return resString + "." + remain.ToString();
  57. }
  58. }
  59. public static string RandomString(int size, bool lowerCase)
  60. {
  61. StringBuilder builder = new StringBuilder();
  62. Random random = new Random();
  63. char ch;
  64. for (int i = 0; i < size; i++)
  65. {
  66. ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
  67. builder.Append(ch);
  68. }
  69. if (lowerCase)
  70. return builder.ToString().ToLower();
  71. return builder.ToString();
  72. }
  73. public class Constant
  74. {
  75. public const String SERVICE_ID = "3";
  76. public const String PARENT_ID = "-1";
  77. public const String NUMBER_ROW_ON_PAGE = "10";
  78. public const String GET_ALL = "-1";
  79. //
  80. public const String SUCCESS = "0";
  81. public const String ERROR = "-1";
  82. public const String BOTS = "1";
  83. public const String GROUPS = "2";
  84. public const String SCHEDULES = "3";
  85. public const String CONFIGS = "4";
  86. public const String SENDMAIL = "5";
  87. public const String SERVICE_CONFIG = "6";
  88. public const int MAX_SCHEDULE_STATUS = 5;
  89. public const int MAX_GROUP_STATUS = 2;
  90. public const int MAX_BOT_STATUS = 1;
  91. public const int MAX_WARNING_STATUS = 2;
  92. public const String DISABLE = "0";
  93. public const String ENABLE = "1";
  94. public const String MONEY_GET = "0";
  95. public const String SUBS_GET = "1";
  96. public const int MAX_GET = 2;
  97. public const int MAX_TABLE = 5;
  98. public const String ONLY_REVEUNUE = "0";
  99. public const String ALL_REVEUNUE = "1";
  100. public const int MAX_FILE = 2;
  101. public const String PAYMENT_FILE = "0";
  102. public const String INVOICE_FILE = "1";
  103. public const String SHOW_FILE = "1";
  104. public const String SAVE_FILE = "2";
  105. public const String DISABLE_GET_DATA = "0";
  106. public const String ENABLE_GET_DATA_AND_WARNING = "1";
  107. public const String ENABLE_GET_DATA_AND_NOT_WARNING = "2";
  108. }
  109. public static String convertNameTable(String tableType)
  110. {
  111. switch (tableType)
  112. {
  113. case "1": return "Cấu hình người gửi";
  114. case "2": return "Cấu hình người nhận";
  115. case "3": return "Cấu hình lập lịch gửi";
  116. case "4": return "Cấu hình configuration";
  117. case "5": return "Cấu hình gửi email";
  118. case "6": return "Cấu hình thêm mới dịch vụ";
  119. default: return "NULL";
  120. }
  121. }
  122. public static String convertNameTypeGet(String typeGet)
  123. {
  124. switch (typeGet)
  125. {
  126. case "0": return "Money Report";
  127. case "1": return "Subscribers Report";
  128. default: return "NULL";
  129. }
  130. }
  131. public static String convertScheduleStatus(int status)
  132. {
  133. switch (status)
  134. {
  135. case 0: return "Disable";
  136. case 1: return "Reminder one time";
  137. case 2: return "Reminder hour by hour";
  138. case 3: return "Reminder day by day";
  139. case 4: return "Reminder week by week";
  140. case 5: return "Reminder month by month";
  141. default: return "NULL";
  142. }
  143. }
  144. public static String convertBotStatus(int status)
  145. {
  146. switch (status)
  147. {
  148. case 0: return "Disable";
  149. case 1: return "Get and warning";
  150. case 2: return "Get and not warning";
  151. default: return "NULL";
  152. }
  153. }
  154. public static String convertServiceState(int state)
  155. {
  156. switch (state)
  157. {
  158. case 0: return "Không";
  159. case 1: return "Có";
  160. default: return "NULL";
  161. }
  162. }
  163. public static String convertGroupStatus(int status)
  164. {
  165. switch (status)
  166. {
  167. case 0: return "Disable";
  168. case 1: return "Communication";
  169. case 2: return "Alarm";
  170. default: return "NULL";
  171. }
  172. }
  173. public static String convertSendMailStatus(int status)
  174. {
  175. switch (status)
  176. {
  177. case 0: return "Disable";
  178. case 1: return "Enable";
  179. default: return "NULL";
  180. }
  181. }
  182. public static string ConvertListType(String type)
  183. {
  184. switch (type)
  185. {
  186. case "0": return "Payment file";
  187. case "1": return "Invoice file";
  188. default: return type + " Unknown";
  189. }
  190. }
  191. public static String ReadDocFileToHtml()
  192. {
  193. String html = System.IO.File.ReadAllText("./resources/payment_code_all.html");
  194. return html;
  195. }
  196. public static bool InvoiceNatcomInterlandDumpt(Contract contract)
  197. {
  198. try
  199. {
  200. string[] validformats = new[] { "MM/dd/yyyy", "yyyy/MM/dd", "MM/dd/yyyy HH:mm:ss", "dd-MMM-yyyy",
  201. "MM/dd/yyyy hh:mm tt", "yyyy-MM-dd HH:mm:ss, fff", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss.fff", "yyyy-MM-dd"};
  202. DateTime convertTime = DateTime.ParseExact(contract.time, validformats,
  203. CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
  204. // Creating a new document.
  205. WordDocument document = new WordDocument();
  206. // Setting document page margins.
  207. MarginsF pagemargins = new MarginsF();
  208. pagemargins.Bottom = 20;
  209. pagemargins.Top = 20;
  210. pagemargins.Left = 75;
  211. pagemargins.Right = 75;
  212. // Assigning document page margins to the current section.
  213. IWSection section = document.AddSection();
  214. section.PageSetup.Margins = pagemargins;
  215. section.AddParagraph();
  216. IWTable table = section.AddTable();
  217. int rowNum = 7, columnNum = 2;
  218. RowFormat format = new RowFormat();
  219. table.ResetCells(rowNum, columnNum);
  220. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  221. float tableWidth = table.Width;
  222. //table.TableFormat.BackColor = Color.FromArgb(192, 192, 192);
  223. table.Rows[0].Cells[0].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
  224. table.Rows[0].Cells[1].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
  225. table.Rows[2].Cells[0].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
  226. table.Rows[2].Cells[1].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
  227. table.Rows[4].Cells[0].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
  228. table.Rows[4].Cells[1].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
  229. for (int i = 0; i < columnNum; i++)
  230. {
  231. for (int j = 0; j < rowNum; j++)
  232. {
  233. WTableCell cell = table.Rows[j].Cells[i];
  234. cell.Width = (float)(i == 0 ? tableWidth * 0.5 : tableWidth * 0.5);
  235. cell.CellFormat.Paddings.Top = 5;
  236. cell.CellFormat.Paddings.Bottom = 5;
  237. cell.CellFormat.Paddings.Left = 5;
  238. cell.CellFormat.Paddings.Right = 5;
  239. if (i == 0)
  240. {
  241. if (j == 6)
  242. {
  243. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  244. cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
  245. cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
  246. cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
  247. }
  248. else if (j == 1 || j == 2 || j == 5 || j == 4)
  249. {
  250. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  251. cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
  252. cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
  253. }
  254. else
  255. {
  256. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  257. cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
  258. }
  259. }
  260. else if (i == 1)
  261. {
  262. if (j == 6)
  263. {
  264. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  265. cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
  266. cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
  267. }
  268. else if (j == 1 || j == 2 || j == 5 || j == 4)
  269. {
  270. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  271. cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
  272. cell.CellFormat.Borders.Left.BorderType = BorderStyle.Single;
  273. }
  274. else
  275. {
  276. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  277. }
  278. }
  279. }
  280. }
  281. table.ApplyHorizontalMerge(0, 0, 1);
  282. IWParagraph para = table[0, 0].AddParagraph();
  283. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  284. IWTextRange textRange = para.AppendText("COMMERCIAL INVOICE");
  285. textRange.CharacterFormat.FontName = "Times New Roman";
  286. textRange.CharacterFormat.FontSize = 16;
  287. textRange.CharacterFormat.Bold = true;
  288. //para = table[0, 0].AddParagraph();
  289. //para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  290. //textRange = para.AppendText("No: " + convertTime.ToString("ddMMyyyy") + "-" + contract.id);
  291. //textRange.CharacterFormat.FontName = "Times New Roman";
  292. //textRange.CharacterFormat.FontSize = 13;
  293. //textRange.CharacterFormat.Bold = true;
  294. para = table[0, 0].AddParagraph();
  295. para = table[1, 0].AddParagraph();
  296. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  297. textRange = para.AppendText("DATE OF EXPORT");
  298. textRange.CharacterFormat.FontName = "Times New Roman";
  299. textRange.CharacterFormat.FontSize = 11;
  300. textRange.CharacterFormat.Bold = true;
  301. para = table[1, 0].AddParagraph();
  302. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  303. textRange = para.AppendText(convertTime.ToString("MMMM/yyyy"));
  304. textRange.CharacterFormat.FontName = "Times New Roman";
  305. textRange.CharacterFormat.FontSize = 11;
  306. textRange.CharacterFormat.Bold = false;
  307. para = table[1, 0].AddParagraph();
  308. para = table[1, 1].AddParagraph();
  309. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  310. textRange = para.AppendText("INVOICE NUMBER: " + convertTime.ToString("MM") + contract.id + "/" + convertTime.ToString("yyyy"));
  311. textRange.CharacterFormat.FontName = "Times New Roman";
  312. textRange.CharacterFormat.FontSize = 11;
  313. textRange.CharacterFormat.Bold = true;
  314. //para = table[1, 1].AddParagraph();
  315. //para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  316. //String d1 = (int.Parse(contract.id) < 10 ? "0" + contract.id : contract.id) + "/VTL-" + contract.syntaxConpany + "/VAS/" + convertTime.ToString("yyyy");
  317. //textRange = para.AppendText(convertTime.ToString("MM") + contract.id + "/" + convertTime.ToString("yyyy"));
  318. //textRange.CharacterFormat.FontName = "Times New Roman";
  319. //textRange.CharacterFormat.FontSize = 11;
  320. //textRange.CharacterFormat.Bold = false;
  321. para = table[1, 1].AddParagraph();
  322. para = table[2, 0].AddParagraph();
  323. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  324. textRange = para.AppendText("PROVIDER");
  325. textRange.CharacterFormat.FontName = "Times New Roman";
  326. textRange.CharacterFormat.FontSize = 11;
  327. textRange.CharacterFormat.Bold = true;
  328. para = table[2, 1].AddParagraph();
  329. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  330. textRange = para.AppendText("BUYER");
  331. textRange.CharacterFormat.FontName = "Times New Roman";
  332. textRange.CharacterFormat.FontSize = 11;
  333. textRange.CharacterFormat.Bold = true;
  334. para = table[3, 0].AddParagraph();
  335. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  336. textRange = para.AppendText("NAME: " + contract.company);
  337. textRange.CharacterFormat.FontName = "Times New Roman";
  338. textRange.CharacterFormat.FontSize = 11;
  339. textRange.CharacterFormat.Bold = false;
  340. para = table[3, 0].AddParagraph();
  341. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  342. textRange = para.AppendText("Address: " + contract.address);
  343. textRange.CharacterFormat.FontName = "Times New Roman";
  344. textRange.CharacterFormat.FontSize = 11;
  345. textRange.CharacterFormat.Bold = false;
  346. //para = table[3, 0].AddParagraph();
  347. //para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  348. //textRange = para.AppendText("Tax code: " + "0108453894");
  349. //textRange.CharacterFormat.FontName = "Times New Roman";
  350. //textRange.CharacterFormat.FontSize = 11;
  351. //textRange.CharacterFormat.Bold = false;
  352. para = table[3, 0].AddParagraph();
  353. para = table[3, 1].AddParagraph();
  354. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  355. textRange = para.AppendText("NAME: " + contract.telco);
  356. textRange.CharacterFormat.FontName = "Times New Roman";
  357. textRange.CharacterFormat.FontSize = 11;
  358. textRange.CharacterFormat.Bold = false;
  359. para = table[3, 1].AddParagraph();
  360. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  361. textRange = para.AppendText("Address: " + contract.addressTelco);
  362. textRange.CharacterFormat.FontName = "Times New Roman";
  363. textRange.CharacterFormat.FontSize = 11;
  364. textRange.CharacterFormat.Bold = false;
  365. //para = table[3, 1].AddParagraph();
  366. //para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  367. //textRange = para.AppendText("Tax code: " + "1150150");
  368. //textRange.CharacterFormat.FontName = "Times New Roman";
  369. //textRange.CharacterFormat.FontSize = 11;
  370. //textRange.CharacterFormat.Bold = false;
  371. para = table[3, 1].AddParagraph();
  372. para = table[4, 0].AddParagraph();
  373. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  374. textRange = para.AppendText("DEFINITION OF PAYMENT");
  375. textRange.CharacterFormat.FontName = "Times New Roman";
  376. textRange.CharacterFormat.FontSize = 11;
  377. textRange.CharacterFormat.Bold = true;
  378. IWTable table2 = table[4, 1].AddTable();
  379. rowNum = 1; columnNum = 3;
  380. table2.ResetCells(rowNum, columnNum);
  381. table2.TableFormat.HorizontalAlignment = RowAlignment.Center;
  382. tableWidth = table2.Width;
  383. for (int i = 0; i < columnNum; i++)
  384. {
  385. for (int j = 0; j < rowNum; j++)
  386. {
  387. WTableCell cell = table2.Rows[j].Cells[i];
  388. if (i == 1)
  389. {
  390. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  391. cell.CellFormat.Borders.Left.BorderType = BorderStyle.Single;
  392. cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
  393. }
  394. else
  395. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  396. }
  397. }
  398. IWParagraph para2 = table2[0, 0].AddParagraph();
  399. para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  400. textRange = para2.AppendText("QUANTITY");
  401. textRange.CharacterFormat.FontName = "Times New Roman";
  402. textRange.CharacterFormat.FontSize = 10;
  403. textRange.CharacterFormat.Bold = true;
  404. para2 = table2[0, 1].AddParagraph();
  405. para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  406. textRange = para2.AppendText("UNIT PRICE (USD)");
  407. textRange.CharacterFormat.FontName = "Times New Roman";
  408. textRange.CharacterFormat.FontSize = 10;
  409. textRange.CharacterFormat.Bold = true;
  410. para2 = table2[0, 2].AddParagraph();
  411. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  412. textRange = para2.AppendText("TOTAL (USD)");
  413. textRange.CharacterFormat.FontName = "Times New Roman";
  414. textRange.CharacterFormat.FontSize = 10;
  415. textRange.CharacterFormat.Bold = true;
  416. //
  417. para = table[5, 0].AddParagraph();
  418. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  419. textRange = para.AppendText(contract.service + " SHARING REVENUE OF " + convertTime.AddMonths(-1).ToString("MMMM yyyy"));
  420. textRange.CharacterFormat.FontName = "Times New Roman";
  421. textRange.CharacterFormat.FontSize = 11;
  422. textRange.CharacterFormat.Bold = false;
  423. para = table[5, 0].AddParagraph();
  424. table2 = table[5, 1].AddTable();
  425. rowNum = 1; columnNum = 3;
  426. table2.ResetCells(rowNum, columnNum);
  427. table2.TableFormat.HorizontalAlignment = RowAlignment.Center;
  428. tableWidth = table2.Width;
  429. for (int i = 0; i < columnNum; i++)
  430. {
  431. for (int j = 0; j < rowNum; j++)
  432. {
  433. WTableCell cell = table2.Rows[j].Cells[i];
  434. cell.CellFormat.Paddings.Top = 5;
  435. cell.CellFormat.Paddings.Bottom = 5;
  436. cell.CellFormat.Paddings.Left = 5;
  437. cell.CellFormat.Paddings.Right = 5;
  438. if (i == 1)
  439. {
  440. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  441. cell.CellFormat.Borders.Left.BorderType = BorderStyle.Single;
  442. cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
  443. }
  444. else
  445. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  446. }
  447. }
  448. para2 = table2[0, 0].AddParagraph();
  449. para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  450. textRange = para2.AppendText("1");
  451. textRange.CharacterFormat.FontName = "Times New Roman";
  452. textRange.CharacterFormat.FontSize = 11;
  453. textRange.CharacterFormat.Bold = false;
  454. para2 = table2[0, 0].AddParagraph();
  455. para2 = table2[0, 0].AddParagraph();
  456. para2 = table2[0, 1].AddParagraph();
  457. para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  458. textRange = para2.AppendText(int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
  459. textRange.CharacterFormat.FontName = "Times New Roman";
  460. textRange.CharacterFormat.FontSize = 11;
  461. textRange.CharacterFormat.Bold = false;
  462. para2 = table2[0, 1].AddParagraph();
  463. para2 = table2[0, 1].AddParagraph();
  464. para2 = table2[0, 2].AddParagraph();
  465. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  466. textRange = para2.AppendText(int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
  467. textRange.CharacterFormat.FontName = "Times New Roman";
  468. textRange.CharacterFormat.FontSize = 11;
  469. textRange.CharacterFormat.Bold = false;
  470. para2 = table2[0, 2].AddParagraph();
  471. para2 = table2[0, 2].AddParagraph();
  472. para = table[6, 0].AddParagraph();
  473. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  474. textRange = para.AppendText("TOTAL");
  475. textRange.CharacterFormat.FontName = "Times New Roman";
  476. textRange.CharacterFormat.FontSize = 12;
  477. textRange.CharacterFormat.Bold = true;
  478. para = table[6, 0].AddParagraph();
  479. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  480. textRange = para.AppendText("By word:");
  481. textRange.CharacterFormat.FontName = "Times New Roman";
  482. textRange.CharacterFormat.FontSize = 11;
  483. textRange.CharacterFormat.Bold = true;
  484. para = table[6, 1].AddParagraph();
  485. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Right;
  486. textRange = para.AppendText(int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
  487. textRange.CharacterFormat.FontName = "Times New Roman";
  488. textRange.CharacterFormat.FontSize = 11;
  489. textRange.CharacterFormat.Bold = true;
  490. para = table[6, 1].AddParagraph();
  491. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  492. textRange = para.AppendText(ConvertAmount(double.Parse(contract.money)) + " Dollars.");
  493. textRange.CharacterFormat.FontName = "Times New Roman";
  494. textRange.CharacterFormat.FontSize = 10;
  495. textRange.CharacterFormat.Bold = true;
  496. para = table[6, 0].AddParagraph();
  497. para = table[6, 1].AddParagraph();
  498. // content
  499. //Appends paragraph.
  500. IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();
  501. paragraph = section.AddParagraph();
  502. paragraph = section.AddParagraph();
  503. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  504. textRange = paragraph.AppendText("Please remit payment to:") as WTextRange;
  505. textRange.CharacterFormat.FontSize = 11;
  506. textRange.CharacterFormat.FontName = "Times New Roman";
  507. textRange.CharacterFormat.Bold = true;
  508. paragraph = section.AddParagraph();
  509. table = section.AddTable();
  510. rowNum = 5; columnNum = 2;
  511. table.ResetCells(rowNum, columnNum);
  512. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  513. tableWidth = table.Width;
  514. for (int i = 0; i < columnNum; i++)
  515. {
  516. for (int j = 0; j < rowNum; j++)
  517. {
  518. WTableCell cell = table.Rows[j].Cells[i];
  519. cell.Width = (float)(i == 0 ? tableWidth * 0.3 : tableWidth * 0.7);
  520. cell.CellFormat.Paddings.Top = 5;
  521. cell.CellFormat.Paddings.Bottom = 5;
  522. cell.CellFormat.Paddings.Left = 5;
  523. cell.CellFormat.Paddings.Right = 5;
  524. if (i == 0)
  525. {
  526. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  527. cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
  528. cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
  529. cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
  530. }
  531. else if (i == 1)
  532. {
  533. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  534. cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
  535. cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
  536. }
  537. }
  538. }
  539. para = table[0, 0].AddParagraph();
  540. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  541. textRange = para.AppendText("Name of Beneficiary");
  542. textRange.CharacterFormat.FontName = "Times New Roman";
  543. textRange.CharacterFormat.FontSize = 11;
  544. textRange.CharacterFormat.Bold = false;
  545. para = table[0, 1].AddParagraph();
  546. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  547. textRange = para.AppendText(contract.beneficiary);
  548. textRange.CharacterFormat.FontName = "Times New Roman";
  549. textRange.CharacterFormat.FontSize = 11;
  550. textRange.CharacterFormat.Bold = false;
  551. para = table[1, 0].AddParagraph();
  552. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  553. textRange = para.AppendText("Address");
  554. textRange.CharacterFormat.FontName = "Times New Roman";
  555. textRange.CharacterFormat.FontSize = 11;
  556. textRange.CharacterFormat.Bold = false;
  557. para = table[1, 1].AddParagraph();
  558. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  559. textRange = para.AppendText(contract.address);
  560. textRange.CharacterFormat.FontName = "Times New Roman";
  561. textRange.CharacterFormat.FontSize = 11;
  562. textRange.CharacterFormat.Bold = false;
  563. para = table[2, 0].AddParagraph();
  564. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  565. textRange = para.AppendText("Name of Beneficiary’s bank");
  566. textRange.CharacterFormat.FontName = "Times New Roman";
  567. textRange.CharacterFormat.FontSize = 11;
  568. textRange.CharacterFormat.Bold = false;
  569. para = table[2, 1].AddParagraph();
  570. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  571. textRange = para.AppendText(contract.bank);
  572. textRange.CharacterFormat.FontName = "Times New Roman";
  573. textRange.CharacterFormat.FontSize = 11;
  574. textRange.CharacterFormat.Bold = false;
  575. para = table[3, 0].AddParagraph();
  576. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  577. textRange = para.AppendText("Account number");
  578. textRange.CharacterFormat.FontName = "Times New Roman";
  579. textRange.CharacterFormat.FontSize = 11;
  580. textRange.CharacterFormat.Bold = false;
  581. para = table[3, 1].AddParagraph();
  582. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  583. textRange = para.AppendText(contract.account);
  584. textRange.CharacterFormat.FontName = "Times New Roman";
  585. textRange.CharacterFormat.FontSize = 11;
  586. textRange.CharacterFormat.Bold = false;
  587. para = table[4, 0].AddParagraph();
  588. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  589. textRange = para.AppendText("SWIFT Code");
  590. textRange.CharacterFormat.FontName = "Times New Roman";
  591. textRange.CharacterFormat.FontSize = 11;
  592. textRange.CharacterFormat.Bold = false;
  593. para = table[4, 1].AddParagraph();
  594. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  595. textRange = para.AppendText(contract.swiftCode);
  596. textRange.CharacterFormat.FontName = "Times New Roman";
  597. textRange.CharacterFormat.FontSize = 11;
  598. textRange.CharacterFormat.Bold = false;
  599. paragraph = section.AddParagraph();
  600. table = section.AddTable();
  601. rowNum = 1; columnNum = 2;
  602. table.ResetCells(rowNum, columnNum);
  603. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  604. tableWidth = table.Width;
  605. table.TableFormat.Borders.Color = Color.White;
  606. for (int i = 0; i < columnNum; i++)
  607. {
  608. for (int j = 0; j < rowNum; j++)
  609. {
  610. WTableCell cell = table.Rows[j].Cells[i];
  611. cell.Width = (float)(i == 0 ? tableWidth * 0.6 : tableWidth * 0.4);
  612. cell.CellFormat.Paddings.Top = 5;
  613. cell.CellFormat.Paddings.Bottom = 5;
  614. cell.CellFormat.Paddings.Left = 5;
  615. cell.CellFormat.Paddings.Right = 5;
  616. cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
  617. }
  618. }
  619. para = table[0, 1].AddParagraph();
  620. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  621. textRange = para.AppendText("SIGNATURE");
  622. textRange.CharacterFormat.FontName = "Times New Roman";
  623. textRange.CharacterFormat.FontSize = 11;
  624. textRange.CharacterFormat.Bold = true;
  625. //Saves the Word document to MemoryStream
  626. MemoryStream stream = new MemoryStream();
  627. document.Save(stream, FormatType.Docx);
  628. stream.Position = 0;
  629. bool exists = System.IO.Directory.Exists("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
  630. if (!exists)
  631. System.IO.Directory.CreateDirectory("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
  632. FileStream outputStream = new FileStream("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy") + "/" + contract.id + "_" + contract.syntaxTelco + "_invoice_" + contract.syntaxConpany + ".docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
  633. document.Save(outputStream, FormatType.Docx);
  634. document.Close();
  635. outputStream.Flush();
  636. outputStream.Dispose();
  637. return true;
  638. }
  639. catch (Exception ex)
  640. {
  641. log.Error("Exp: " + ex);
  642. return false;
  643. }
  644. }
  645. public static bool PaymentNatcomAllDumpt(Contract contract)
  646. {
  647. try
  648. {
  649. string[] validformats = new[] { "dd/MM/yyyy", "dd-MMM-yyyy" };
  650. DateTime convertTime = DateTime.ParseExact(contract.time, validformats,
  651. CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
  652. // Creating a new document.
  653. WordDocument document = new WordDocument();
  654. // Setting document page margins.
  655. MarginsF pagemargins = new MarginsF();
  656. pagemargins.Bottom = 20;
  657. pagemargins.Top = 20;
  658. pagemargins.Left = 75;
  659. pagemargins.Right = 75;
  660. // Assigning document page margins to the current section.
  661. IWSection section = document.AddSection();
  662. section.PageSetup.Margins = pagemargins;
  663. section.AddParagraph();
  664. IWTable table = section.AddTable();
  665. int rowNum = 1, columnNum = 2;
  666. RowFormat format = new RowFormat();
  667. table.ResetCells(rowNum, columnNum);
  668. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  669. for (int i = 0; i < columnNum; i++)
  670. {
  671. for (int j = 0; j < rowNum; j++)
  672. {
  673. WTableCell cell = table.Rows[j].Cells[i];
  674. cell.Width = (float)(i == 0 ? table.Width * 0.5 : table.Width * 0.5);
  675. cell.CellFormat.Paddings.Top = 5;
  676. cell.CellFormat.Paddings.Bottom = 5;
  677. cell.CellFormat.Paddings.Left = 5;
  678. cell.CellFormat.Paddings.Right = 5;
  679. }
  680. }
  681. IWParagraph para = table[0, 0].AddParagraph();
  682. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  683. IWTextRange textRange = para.AppendText(contract.company);
  684. textRange.CharacterFormat.FontName = "Times New Roman";
  685. textRange.CharacterFormat.FontSize = 11;
  686. textRange.CharacterFormat.Bold = true;
  687. //textRange = table[0, 0].AddParagraph().AppendText("");
  688. String d1 = "NO: " + "07/2019" + "/" + "MTV " + contract.syntaxConpany + "NV - " + contract.syntaxTelco + " - " + contract.service;
  689. para = table[0, 0].AddParagraph();
  690. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  691. textRange = para.AppendText(d1);
  692. textRange.CharacterFormat.FontName = "Times New Roman";
  693. textRange.CharacterFormat.FontSize = 11;
  694. textRange.CharacterFormat.Bold = false;
  695. para = table[0, 1].AddParagraph();
  696. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  697. textRange = para.AppendText("SOCIALIST REPUBLIC OF VIETNAM");
  698. textRange.CharacterFormat.FontName = "Times New Roman";
  699. textRange.CharacterFormat.FontSize = 11;
  700. textRange.CharacterFormat.Bold = true;
  701. para = table[0, 1].AddParagraph();
  702. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  703. textRange = para.AppendText("Freedom - Equality - Fraternity");
  704. textRange.CharacterFormat.FontName = "Times New Roman";
  705. textRange.CharacterFormat.FontSize = 11;
  706. textRange.CharacterFormat.Bold = true;
  707. textRange = table[0, 1].AddParagraph().AppendText("");
  708. String d2 = "Hanoi, " + convertTime.ToString("dd-MMMM, yyyy");
  709. para = table[0, 1].AddParagraph();
  710. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  711. textRange = para.AppendText(d2);
  712. textRange.CharacterFormat.FontName = "Times New Roman";
  713. textRange.CharacterFormat.FontSize = 11;
  714. textRange.CharacterFormat.Bold = false;
  715. // content
  716. //Appends paragraph.
  717. IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();
  718. paragraph = section.AddParagraph();
  719. paragraph = section.AddParagraph();
  720. paragraph = section.AddParagraph();
  721. paragraph = section.AddParagraph();
  722. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  723. textRange = paragraph.AppendText("PAYMENT REQUEST") as WTextRange;
  724. textRange.CharacterFormat.FontSize = 15;
  725. textRange.CharacterFormat.FontName = "Times New Roman";
  726. textRange.CharacterFormat.Bold = true;
  727. paragraph = section.AddParagraph();
  728. paragraph = section.AddParagraph();
  729. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  730. textRange = paragraph.AppendText("To " + contract.telco) as WTextRange;
  731. textRange.CharacterFormat.FontSize = 15;
  732. textRange.CharacterFormat.FontName = "Times New Roman";
  733. textRange.CharacterFormat.Bold = true;
  734. paragraph = section.AddParagraph();
  735. paragraph = section.AddParagraph();
  736. paragraph = section.AddParagraph();
  737. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  738. textRange = paragraph.AppendText(" " + "According to the contract No ") as WTextRange;
  739. textRange.CharacterFormat.FontSize = 11;
  740. textRange.CharacterFormat.FontName = "Times New Roman";
  741. textRange.CharacterFormat.Bold = false;
  742. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  743. textRange = paragraph.AppendText(contract.contractCode) as WTextRange;
  744. textRange.CharacterFormat.FontSize = 11;
  745. textRange.CharacterFormat.FontName = "Times New Roman";
  746. textRange.CharacterFormat.Bold = true;
  747. textRange = paragraph.AppendText(" service provision contract and if there is content of contract") as WTextRange;
  748. textRange.CharacterFormat.FontSize = 11;
  749. textRange.CharacterFormat.FontName = "Times New Roman";
  750. textRange.CharacterFormat.Bold = true;
  751. textRange = paragraph.AppendText(" regarding to providing service on " + contract.syntaxTelco + " Mobile network between " + contract.syntaxTelco + " and ") as WTextRange;
  752. textRange.CharacterFormat.FontSize = 11;
  753. textRange.CharacterFormat.FontName = "Times New Roman";
  754. textRange.CharacterFormat.Bold = false;
  755. textRange = paragraph.AppendText(contract.company + ".") as WTextRange;
  756. textRange.CharacterFormat.FontSize = 11;
  757. textRange.CharacterFormat.FontName = "Times New Roman";
  758. textRange.CharacterFormat.Bold = true;
  759. paragraph = section.AddParagraph();
  760. paragraph = section.AddParagraph();
  761. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  762. textRange = paragraph.AppendText(" " + "According to COMMERCIAL INVOICE No: ") as WTextRange;
  763. textRange.CharacterFormat.FontSize = 11;
  764. textRange.CharacterFormat.FontName = "Times New Roman";
  765. textRange.CharacterFormat.Bold = false;
  766. String d3 = convertTime.ToString("ddMMyyyy") + "-" + contract.id + " " + contract.service;
  767. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  768. textRange = paragraph.AppendText(d3) as WTextRange;
  769. textRange.CharacterFormat.FontSize = 11;
  770. textRange.CharacterFormat.FontName = "Times New Roman";
  771. textRange.CharacterFormat.Bold = true;
  772. paragraph = section.AddParagraph();
  773. paragraph = section.AddParagraph();
  774. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  775. textRange = paragraph.AppendText(" " + "According to Form of Yield Confirmation – Income of ") as WTextRange;
  776. textRange.CharacterFormat.FontSize = 11;
  777. textRange.CharacterFormat.FontName = "Times New Roman";
  778. textRange.CharacterFormat.Bold = false;
  779. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  780. textRange = paragraph.AppendText(contract.service) as WTextRange;
  781. textRange.CharacterFormat.FontSize = 11;
  782. textRange.CharacterFormat.FontName = "Times New Roman";
  783. textRange.CharacterFormat.Bold = true;
  784. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  785. textRange = paragraph.AppendText(" Service between " + contract.telco + " and ") as WTextRange;
  786. textRange.CharacterFormat.FontSize = 11;
  787. textRange.CharacterFormat.FontName = "Times New Roman";
  788. textRange.CharacterFormat.Bold = false;
  789. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  790. textRange = paragraph.AppendText(contract.company) as WTextRange;
  791. textRange.CharacterFormat.FontSize = 11;
  792. textRange.CharacterFormat.FontName = "Times New Roman";
  793. textRange.CharacterFormat.Bold = true;
  794. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  795. textRange = paragraph.AppendText(" for month ") as WTextRange;
  796. textRange.CharacterFormat.FontSize = 11;
  797. textRange.CharacterFormat.FontName = "Times New Roman";
  798. textRange.CharacterFormat.Bold = false;
  799. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  800. textRange = paragraph.AppendText(convertTime.AddMonths(-1).ToString("MMMM yyyy") + ".") as WTextRange;
  801. textRange.CharacterFormat.FontSize = 11;
  802. textRange.CharacterFormat.FontName = "Times New Roman";
  803. textRange.CharacterFormat.Bold = true;
  804. paragraph = section.AddParagraph();
  805. paragraph = section.AddParagraph();
  806. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  807. textRange = paragraph.AppendText(" " + contract.syntaxTelco + " must make payment to " + contract.company + " for " + convertTime.AddMonths(-1).ToString("MMMM yyyy") + " : ") as WTextRange;
  808. textRange.CharacterFormat.FontSize = 11;
  809. textRange.CharacterFormat.FontName = "Times New Roman";
  810. textRange.CharacterFormat.Bold = false;
  811. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  812. textRange = paragraph.AppendText(contract.company) as WTextRange;
  813. textRange.CharacterFormat.FontSize = 11;
  814. textRange.CharacterFormat.FontName = "Times New Roman";
  815. textRange.CharacterFormat.Bold = true;
  816. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  817. textRange = paragraph.AppendText(" for ") as WTextRange;
  818. textRange.CharacterFormat.FontSize = 11;
  819. textRange.CharacterFormat.FontName = "Times New Roman";
  820. textRange.CharacterFormat.Bold = false;
  821. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  822. textRange = paragraph.AppendText(convertTime.ToString("MMMM yyyy") + " : ") as WTextRange;
  823. textRange.CharacterFormat.FontSize = 11;
  824. textRange.CharacterFormat.FontName = "Times New Roman";
  825. textRange.CharacterFormat.Bold = true;
  826. paragraph = section.AddParagraph();
  827. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  828. textRange = paragraph.AppendText(" " + "$ " + int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture)) as WTextRange;
  829. textRange.CharacterFormat.FontSize = 11;
  830. textRange.CharacterFormat.FontName = "Times New Roman";
  831. textRange.CharacterFormat.Bold = true;
  832. paragraph = section.AddParagraph();
  833. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  834. textRange = paragraph.AppendText(" " + "Total : $ " + int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture)) as WTextRange;
  835. textRange.CharacterFormat.FontSize = 11;
  836. textRange.CharacterFormat.FontName = "Times New Roman";
  837. textRange.CharacterFormat.Bold = true;
  838. //paragraph = section.AddParagraph();
  839. paragraph = section.AddParagraph();
  840. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  841. textRange = paragraph.AppendText("In words : " + ConvertAmount(double.Parse(contract.money)) + " dollars./.") as WTextRange;
  842. textRange.CharacterFormat.FontSize = 11;
  843. textRange.CharacterFormat.FontName = "Times New Roman";
  844. textRange.CharacterFormat.Bold = true;
  845. //paragraph = section.AddParagraph();
  846. paragraph = section.AddParagraph();
  847. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  848. textRange = paragraph.AppendText(" " + "Thus, you are requested to transfer the payment above and fax us the T/T remittance once available ") as WTextRange;
  849. textRange.CharacterFormat.FontSize = 11;
  850. textRange.CharacterFormat.FontName = "Times New Roman";
  851. textRange.CharacterFormat.Bold = false;
  852. //paragraph = section.AddParagraph();
  853. paragraph = section.AddParagraph();
  854. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  855. textRange = paragraph.AppendText(" " + "Payment method and currency : Telegraphic in USD") as WTextRange;
  856. textRange.CharacterFormat.FontSize = 11;
  857. textRange.CharacterFormat.FontName = "Times New Roman";
  858. textRange.CharacterFormat.Bold = false;
  859. paragraph = section.AddParagraph();
  860. table = section.AddTable();
  861. rowNum = 5; columnNum = 2;
  862. table.ResetCells(rowNum, columnNum);
  863. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  864. float tableWidth = table.Width;
  865. for (int i = 0; i < columnNum; i++)
  866. {
  867. for (int j = 0; j < rowNum; j++)
  868. {
  869. WTableCell cell = table.Rows[j].Cells[i];
  870. cell.Width = (float)(i == 0 ? tableWidth * 0.3 : tableWidth * 0.7);
  871. cell.CellFormat.Paddings.Top = 5;
  872. cell.CellFormat.Paddings.Bottom = 5;
  873. cell.CellFormat.Paddings.Left = 5;
  874. cell.CellFormat.Paddings.Right = 5;
  875. }
  876. }
  877. para = table[0, 0].AddParagraph();
  878. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  879. textRange = para.AppendText("Beneficiary");
  880. textRange.CharacterFormat.FontName = "Times New Roman";
  881. textRange.CharacterFormat.FontSize = 11;
  882. textRange.CharacterFormat.Bold = true;
  883. para = table[1, 0].AddParagraph();
  884. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  885. textRange = para.AppendText("Address");
  886. textRange.CharacterFormat.FontName = "Times New Roman";
  887. textRange.CharacterFormat.FontSize = 11;
  888. textRange.CharacterFormat.Bold = true;
  889. para = table[3, 0].AddParagraph();
  890. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  891. textRange = para.AppendText("Account No.");
  892. textRange.CharacterFormat.FontName = "Times New Roman";
  893. textRange.CharacterFormat.FontSize = 11;
  894. textRange.CharacterFormat.Bold = true;
  895. para = table[2, 0].AddParagraph();
  896. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  897. textRange = para.AppendText("Bank");
  898. textRange.CharacterFormat.FontName = "Times New Roman";
  899. textRange.CharacterFormat.FontSize = 11;
  900. textRange.CharacterFormat.Bold = true;
  901. para = table[4, 0].AddParagraph();
  902. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  903. textRange = para.AppendText("Swift Code");
  904. textRange.CharacterFormat.FontName = "Times New Roman";
  905. textRange.CharacterFormat.FontSize = 11;
  906. textRange.CharacterFormat.Bold = true;
  907. /////--------------
  908. para = table[0, 1].AddParagraph();
  909. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  910. textRange = para.AppendText(contract.beneficiary);
  911. textRange.CharacterFormat.FontName = "Times New Roman";
  912. textRange.CharacterFormat.FontSize = 11;
  913. textRange.CharacterFormat.Bold = true;
  914. para = table[1, 1].AddParagraph();
  915. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  916. textRange = para.AppendText(contract.address);
  917. textRange.CharacterFormat.FontName = "Times New Roman";
  918. textRange.CharacterFormat.FontSize = 11;
  919. textRange.CharacterFormat.Bold = false;
  920. para = table[3, 1].AddParagraph();
  921. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  922. textRange = para.AppendText(contract.account);
  923. textRange.CharacterFormat.FontName = "Times New Roman";
  924. textRange.CharacterFormat.FontSize = 11;
  925. textRange.CharacterFormat.Bold = false;
  926. para = table[2, 1].AddParagraph();
  927. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  928. textRange = para.AppendText(contract.bank);
  929. textRange.CharacterFormat.FontName = "Times New Roman";
  930. textRange.CharacterFormat.FontSize = 11;
  931. textRange.CharacterFormat.Bold = false;
  932. para = table[4, 1].AddParagraph();
  933. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  934. textRange = para.AppendText(contract.swiftCode);
  935. textRange.CharacterFormat.FontName = "Times New Roman";
  936. textRange.CharacterFormat.FontSize = 11;
  937. textRange.CharacterFormat.Bold = false;
  938. paragraph = section.AddParagraph();
  939. paragraph = section.AddParagraph();
  940. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  941. textRange = paragraph.AppendText("Best Regards, ") as WTextRange;
  942. textRange.CharacterFormat.FontSize = 11;
  943. textRange.CharacterFormat.FontName = "Times New Roman";
  944. textRange.CharacterFormat.Bold = false;
  945. table = section.AddTable();
  946. rowNum = 1; columnNum = 2;
  947. table.ResetCells(rowNum, columnNum);
  948. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  949. tableWidth = table.Width;
  950. table.TableFormat.Borders.Color = Color.White;
  951. for (int i = 0; i < columnNum; i++)
  952. {
  953. for (int j = 0; j < rowNum; j++)
  954. {
  955. WTableCell cell = table.Rows[j].Cells[i];
  956. cell.Width = (float)(i == 0 ? tableWidth * 0.2 : tableWidth * 0.8);
  957. cell.CellFormat.Paddings.Top = 5;
  958. cell.CellFormat.Paddings.Bottom = 5;
  959. cell.CellFormat.Paddings.Left = 5;
  960. cell.CellFormat.Paddings.Right = 5;
  961. cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
  962. }
  963. }
  964. para = table[0, 1].AddParagraph();
  965. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  966. textRange = para.AppendText(contract.company);
  967. textRange.CharacterFormat.FontName = "Times New Roman";
  968. textRange.CharacterFormat.FontSize = 11;
  969. textRange.CharacterFormat.Bold = true;
  970. para = table[0, 1].AddParagraph();
  971. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  972. textRange = para.AppendText("Director");
  973. textRange.CharacterFormat.FontName = "Times New Roman";
  974. textRange.CharacterFormat.FontSize = 11;
  975. textRange.CharacterFormat.Bold = true;
  976. //Saves the Word document to MemoryStream
  977. MemoryStream stream = new MemoryStream();
  978. document.Save(stream, FormatType.Docx);
  979. stream.Position = 0;
  980. bool exists = Directory.Exists("./Files/Payments/" + DateTime.Now.ToString("dd_MM_yyyy"));
  981. if (!exists)
  982. Directory.CreateDirectory("./Files/Payments/" + DateTime.Now.ToString("dd_MM_yyyy"));
  983. FileStream outputStream = new FileStream("./Files/Payments/" + DateTime.Now.ToString("dd_MM_yyyy") + "/" + contract.id + "_" + contract.syntaxTelco + "_payment_" + contract.syntaxConpany + ".docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
  984. document.Save(outputStream, FormatType.Docx);
  985. document.Close();
  986. outputStream.Flush();
  987. outputStream.Dispose();
  988. return true;
  989. }
  990. catch (Exception ex)
  991. {
  992. log.Error("Exp: " + ex);
  993. }
  994. return false;
  995. }
  996. public static bool PaymentDumpt(Contract contract)
  997. {
  998. try
  999. {
  1000. string[] validformats = new[] { "dd/MM/yyyy", "dd-MMM-yyyy" };
  1001. DateTime convertTime = DateTime.ParseExact(contract.time, validformats,
  1002. CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
  1003. int coChu = 12;
  1004. // Creating a new document.
  1005. WordDocument document = new WordDocument();
  1006. // Setting document page margins.
  1007. MarginsF pagemargins = new MarginsF();
  1008. pagemargins.Bottom = 20;
  1009. pagemargins.Top = 20;
  1010. pagemargins.Left = 75;
  1011. pagemargins.Right = 75;
  1012. // Assigning document page margins to the current section.
  1013. IWSection section = document.AddSection();
  1014. section.PageSetup.Margins = pagemargins;
  1015. section.AddParagraph();
  1016. IWTable table = section.AddTable();
  1017. int rowNum = 1, columnNum = 2;
  1018. RowFormat format = new RowFormat();
  1019. table.ResetCells(rowNum, columnNum);
  1020. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  1021. for (int i = 0; i < columnNum; i++)
  1022. {
  1023. for (int j = 0; j < rowNum; j++)
  1024. {
  1025. WTableCell cell = table.Rows[j].Cells[i];
  1026. cell.Width = (float)(i == 0 ? table.Width * 0.5 : table.Width * 0.5);
  1027. cell.CellFormat.Paddings.Top = 5;
  1028. cell.CellFormat.Paddings.Bottom = 5;
  1029. cell.CellFormat.Paddings.Left = 5;
  1030. cell.CellFormat.Paddings.Right = 5;
  1031. }
  1032. }
  1033. IWParagraph para = table[0, 0].AddParagraph();
  1034. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1035. IWTextRange textRange = para.AppendText(contract.company);
  1036. textRange.CharacterFormat.FontName = "Times New Roman";
  1037. textRange.CharacterFormat.FontSize = coChu;
  1038. textRange.CharacterFormat.Bold = true;
  1039. //textRange = table[0, 0].AddParagraph().AppendText("");
  1040. String d1 = "NO: " + convertTime.ToString(contract.syntaxConpany == "GTS" ? "ddMM/yyyy" : "MM/yyyy") + "/" + contract.syntaxConpany + " - " + contract.syntaxTelco + " - " + contract.service;
  1041. para = table[0, 0].AddParagraph();
  1042. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1043. textRange = para.AppendText(d1);
  1044. textRange.CharacterFormat.FontName = "Times New Roman";
  1045. textRange.CharacterFormat.FontSize = coChu;
  1046. textRange.CharacterFormat.Bold = false;
  1047. para = table[0, 1].AddParagraph();
  1048. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1049. textRange = para.AppendText("SOCIALIST REPUBLIC OF VIETNAM");
  1050. textRange.CharacterFormat.FontName = "Times New Roman";
  1051. textRange.CharacterFormat.FontSize = coChu;
  1052. textRange.CharacterFormat.Bold = true;
  1053. para = table[0, 1].AddParagraph();
  1054. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1055. textRange = para.AppendText("Freedom - Equality - Fraternity");
  1056. textRange.CharacterFormat.FontName = "Times New Roman";
  1057. textRange.CharacterFormat.FontSize = coChu;
  1058. textRange.CharacterFormat.Bold = true;
  1059. textRange = table[0, 1].AddParagraph().AppendText("");
  1060. String d2 = "Hanoi, " + convertTime.ToString("dd-MMMM, yyyy");
  1061. para = table[0, 1].AddParagraph();
  1062. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1063. textRange = para.AppendText(d2);
  1064. textRange.CharacterFormat.FontName = "Times New Roman";
  1065. textRange.CharacterFormat.FontSize = coChu;
  1066. textRange.CharacterFormat.Bold = false;
  1067. // content
  1068. //Appends paragraph.
  1069. IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();
  1070. paragraph = section.AddParagraph();
  1071. paragraph = section.AddParagraph();
  1072. paragraph = section.AddParagraph();
  1073. paragraph = section.AddParagraph();
  1074. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1075. textRange = paragraph.AppendText("PAYMENT REQUEST") as WTextRange;
  1076. textRange.CharacterFormat.FontSize = 15;
  1077. textRange.CharacterFormat.FontName = "Times New Roman";
  1078. textRange.CharacterFormat.Bold = true;
  1079. paragraph = section.AddParagraph();
  1080. paragraph = section.AddParagraph();
  1081. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1082. textRange = paragraph.AppendText("To: ") as WTextRange;
  1083. textRange.CharacterFormat.FontSize = coChu;
  1084. textRange.CharacterFormat.FontName = "Times New Roman";
  1085. textRange.CharacterFormat.Bold = true;
  1086. paragraph = section.AddParagraph();
  1087. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1088. textRange = paragraph.AppendText(contract.telco) as WTextRange;
  1089. textRange.CharacterFormat.FontSize = coChu;
  1090. textRange.CharacterFormat.FontName = "Times New Roman";
  1091. textRange.CharacterFormat.Bold = true;
  1092. paragraph = section.AddParagraph();
  1093. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1094. textRange = paragraph.AppendText("Taxtcode: 1150150") as WTextRange;
  1095. textRange.CharacterFormat.FontSize = coChu;
  1096. textRange.CharacterFormat.FontName = "Times New Roman";
  1097. textRange.CharacterFormat.Bold = true;
  1098. paragraph = section.AddParagraph();
  1099. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1100. textRange = paragraph.AppendText("According to the contract " + contract.contractCode) as WTextRange;
  1101. textRange.CharacterFormat.FontSize = coChu;
  1102. textRange.CharacterFormat.FontName = "Times New Roman";
  1103. textRange.CharacterFormat.Bold = false;
  1104. textRange = paragraph.AppendText(" service provision contract and content of contract") as WTextRange;
  1105. textRange.CharacterFormat.FontSize = coChu;
  1106. textRange.CharacterFormat.FontName = "Times New Roman";
  1107. textRange.CharacterFormat.Bold = false;
  1108. textRange = paragraph.AppendText(" regarding to providing " + contract.service + " service on " + contract.syntaxTelco + " Mobile network between " + contract.syntaxTelco + " and " + contract.company + ".") as WTextRange;
  1109. textRange.CharacterFormat.FontSize = coChu;
  1110. textRange.CharacterFormat.FontName = "Times New Roman";
  1111. textRange.CharacterFormat.Bold = false;
  1112. paragraph = section.AddParagraph();
  1113. paragraph = section.AddParagraph();
  1114. String d3 = convertTime.ToString(contract.syntaxConpany == "ITL" || contract.syntaxConpany == "INTERLAND" ? "yyyyMMdd" : "ddMMyyyy") + "-" + contract.id;
  1115. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1116. textRange = paragraph.AppendText(" " + "According to COMMERCIAL INVOICE No: " + d3) as WTextRange;
  1117. textRange.CharacterFormat.FontSize = coChu;
  1118. textRange.CharacterFormat.FontName = "Times New Roman";
  1119. textRange.CharacterFormat.Bold = false;
  1120. paragraph = section.AddParagraph();
  1121. paragraph = section.AddParagraph();
  1122. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1123. textRange = paragraph.AppendText(" " + "According to Form of Yield Confirmation – Income of " + contract.service + " Service between " + contract.syntaxTelco + " and " + contract.company + " for month " + convertTime.AddMonths(-1).ToString("MMMM yyyy") + ".") as WTextRange;
  1124. textRange.CharacterFormat.FontSize = coChu;
  1125. textRange.CharacterFormat.FontName = "Times New Roman";
  1126. textRange.CharacterFormat.Bold = false;
  1127. paragraph = section.AddParagraph();
  1128. paragraph = section.AddParagraph();
  1129. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1130. textRange = paragraph.AppendText(" " + contract.syntaxTelco + " must make payment to " + contract.company + " for " + convertTime.AddMonths(-1).ToString("MMMM yyyy") + " : ") as WTextRange;
  1131. textRange.CharacterFormat.FontSize = coChu;
  1132. textRange.CharacterFormat.FontName = "Times New Roman";
  1133. textRange.CharacterFormat.Bold = false;
  1134. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1135. textRange = paragraph.AppendText("$ " + int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture)) as WTextRange;
  1136. textRange.CharacterFormat.FontSize = coChu;
  1137. textRange.CharacterFormat.FontName = "Times New Roman";
  1138. textRange.CharacterFormat.Bold = true;
  1139. paragraph = section.AddParagraph();
  1140. paragraph = section.AddParagraph();
  1141. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1142. textRange = paragraph.AppendText(" " + "Total : $ " + int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture)) as WTextRange;
  1143. textRange.CharacterFormat.FontSize = coChu;
  1144. textRange.CharacterFormat.FontName = "Times New Roman";
  1145. textRange.CharacterFormat.Bold = true;
  1146. paragraph = section.AddParagraph();
  1147. paragraph = section.AddParagraph();
  1148. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1149. textRange = paragraph.AppendText("In words : ") as WTextRange;
  1150. textRange.CharacterFormat.FontSize = coChu;
  1151. textRange.CharacterFormat.FontName = "Times New Roman";
  1152. textRange.CharacterFormat.Bold = false;
  1153. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1154. if (contract.contractCode == "VIETTECH")
  1155. {
  1156. textRange = paragraph.AppendText(ConvertAmount(double.Parse(contract.money)) + " United States Dollars.") as WTextRange;
  1157. }
  1158. else if (contract.contractCode == "ITL" || contract.contractCode == "INTERLAND")
  1159. {
  1160. textRange = paragraph.AppendText(ConvertAmount(double.Parse(contract.money)) + " USD.") as WTextRange;
  1161. }
  1162. else
  1163. {
  1164. textRange = paragraph.AppendText(ConvertAmount(double.Parse(contract.money)) + " dollars./.") as WTextRange;
  1165. }
  1166. textRange.CharacterFormat.FontSize = coChu;
  1167. textRange.CharacterFormat.FontName = "Times New Roman";
  1168. textRange.CharacterFormat.Bold = true;
  1169. textRange.CharacterFormat.Italic = true;
  1170. paragraph = section.AddParagraph();
  1171. paragraph = section.AddParagraph();
  1172. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1173. textRange = paragraph.AppendText(" " + "Thus, you are requested to transfer the payment above and fax us the T/T remittance once available ") as WTextRange;
  1174. textRange.CharacterFormat.FontSize = coChu;
  1175. textRange.CharacterFormat.FontName = "Times New Roman";
  1176. textRange.CharacterFormat.Bold = false;
  1177. paragraph = section.AddParagraph();
  1178. paragraph = section.AddParagraph();
  1179. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1180. textRange = paragraph.AppendText(" " + "Payment method and currency : Telegraphic in USD") as WTextRange;
  1181. textRange.CharacterFormat.FontSize = coChu;
  1182. textRange.CharacterFormat.FontName = "Times New Roman";
  1183. textRange.CharacterFormat.Bold = false;
  1184. paragraph = section.AddParagraph();
  1185. table = section.AddTable();
  1186. rowNum = 5; columnNum = 2;
  1187. table.ResetCells(rowNum, columnNum);
  1188. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  1189. float tableWidth = table.Width;
  1190. for (int i = 0; i < columnNum; i++)
  1191. {
  1192. for (int j = 0; j < rowNum; j++)
  1193. {
  1194. WTableCell cell = table.Rows[j].Cells[i];
  1195. cell.Width = (float)(i == 0 ? tableWidth * 0.3 : tableWidth * 0.7);
  1196. cell.CellFormat.Paddings.Top = 5;
  1197. cell.CellFormat.Paddings.Bottom = 5;
  1198. cell.CellFormat.Paddings.Left = 5;
  1199. cell.CellFormat.Paddings.Right = 5;
  1200. }
  1201. }
  1202. para = table[0, 0].AddParagraph();
  1203. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1204. textRange = para.AppendText(contract.syntaxConpany == "GTS" ? "Name of Beneficiary" : "Beneficiary");
  1205. textRange.CharacterFormat.FontName = "Times New Roman";
  1206. textRange.CharacterFormat.FontSize = coChu;
  1207. textRange.CharacterFormat.Bold = contract.syntaxConpany == "GTS" ? false : true;
  1208. para = table[1, 0].AddParagraph();
  1209. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1210. textRange = para.AppendText("Address");
  1211. textRange.CharacterFormat.FontName = "Times New Roman";
  1212. textRange.CharacterFormat.FontSize = coChu;
  1213. textRange.CharacterFormat.Bold = contract.syntaxConpany == "GTS" ? false : true;
  1214. para = table[2, 0].AddParagraph();
  1215. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1216. textRange = para.AppendText(contract.syntaxConpany == "GTS" ? "Bank account:" : "Account No.");
  1217. textRange.CharacterFormat.FontName = "Times New Roman";
  1218. textRange.CharacterFormat.FontSize = coChu;
  1219. textRange.CharacterFormat.Bold = contract.syntaxConpany == "GTS" ? false : true;
  1220. para = table[3, 0].AddParagraph();
  1221. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1222. textRange = para.AppendText(contract.syntaxConpany == "GTS" ? "Bank Name" : "Bank");
  1223. textRange.CharacterFormat.FontName = "Times New Roman";
  1224. textRange.CharacterFormat.FontSize = coChu;
  1225. textRange.CharacterFormat.Bold = contract.syntaxConpany == "GTS" ? false : true;
  1226. para = table[4, 0].AddParagraph();
  1227. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1228. textRange = para.AppendText("Swift Code:");
  1229. textRange.CharacterFormat.FontName = "Times New Roman";
  1230. textRange.CharacterFormat.FontSize = 11;
  1231. textRange.CharacterFormat.Bold = contract.syntaxConpany == "GTS" ? false : true;
  1232. /////--------------
  1233. para = table[0, 1].AddParagraph();
  1234. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1235. textRange = para.AppendText(contract.beneficiary);
  1236. textRange.CharacterFormat.FontName = "Times New Roman";
  1237. textRange.CharacterFormat.FontSize = coChu;
  1238. textRange.CharacterFormat.Bold = contract.syntaxConpany == "GTS" ? false : true;
  1239. para = table[1, 1].AddParagraph();
  1240. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1241. textRange = para.AppendText(contract.address);
  1242. textRange.CharacterFormat.FontName = "Times New Roman";
  1243. textRange.CharacterFormat.FontSize = coChu;
  1244. textRange.CharacterFormat.Bold = false;
  1245. para = table[2, 1].AddParagraph();
  1246. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1247. textRange = para.AppendText(contract.account);
  1248. textRange.CharacterFormat.FontName = "Times New Roman";
  1249. textRange.CharacterFormat.FontSize = coChu;
  1250. textRange.CharacterFormat.Bold = false;
  1251. para = table[3, 1].AddParagraph();
  1252. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1253. textRange = para.AppendText(contract.bank);
  1254. textRange.CharacterFormat.FontName = "Times New Roman";
  1255. textRange.CharacterFormat.FontSize = coChu;
  1256. textRange.CharacterFormat.Bold = false;
  1257. para = table[4, 1].AddParagraph();
  1258. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1259. textRange = para.AppendText(contract.swiftCode);
  1260. textRange.CharacterFormat.FontName = "Times New Roman";
  1261. textRange.CharacterFormat.FontSize = coChu;
  1262. textRange.CharacterFormat.Bold = false;
  1263. paragraph = section.AddParagraph();
  1264. paragraph = section.AddParagraph();
  1265. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1266. textRange = paragraph.AppendText("Best Regards, ") as WTextRange;
  1267. textRange.CharacterFormat.FontSize = coChu;
  1268. textRange.CharacterFormat.FontName = "Times New Roman";
  1269. textRange.CharacterFormat.Bold = false;
  1270. table = section.AddTable();
  1271. rowNum = 1; columnNum = 2;
  1272. table.ResetCells(rowNum, columnNum);
  1273. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  1274. tableWidth = table.Width;
  1275. table.TableFormat.Borders.Color = Color.White;
  1276. for (int i = 0; i < columnNum; i++)
  1277. {
  1278. for (int j = 0; j < rowNum; j++)
  1279. {
  1280. WTableCell cell = table.Rows[j].Cells[i];
  1281. cell.Width = (float)(i == 0 ? tableWidth * 0.2 : tableWidth * 0.8);
  1282. cell.CellFormat.Paddings.Top = 5;
  1283. cell.CellFormat.Paddings.Bottom = 5;
  1284. cell.CellFormat.Paddings.Left = 5;
  1285. cell.CellFormat.Paddings.Right = 5;
  1286. cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
  1287. }
  1288. }
  1289. para = table[0, 1].AddParagraph();
  1290. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1291. textRange = para.AppendText(contract.company);
  1292. textRange.CharacterFormat.FontName = "Times New Roman";
  1293. textRange.CharacterFormat.FontSize = coChu;
  1294. textRange.CharacterFormat.Bold = true;
  1295. para = table[0, 1].AddParagraph();
  1296. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1297. textRange = para.AppendText("Director");
  1298. textRange.CharacterFormat.FontName = "Times New Roman";
  1299. textRange.CharacterFormat.FontSize = coChu;
  1300. textRange.CharacterFormat.Bold = true;
  1301. //Saves the Word document to MemoryStream
  1302. MemoryStream stream = new MemoryStream();
  1303. document.Save(stream, FormatType.Docx);
  1304. stream.Position = 0;
  1305. bool exists = Directory.Exists("./Files/Payments/" + DateTime.Now.ToString("dd_MM_yyyy"));
  1306. if (!exists)
  1307. Directory.CreateDirectory("./Files/Payments/" + DateTime.Now.ToString("dd_MM_yyyy"));
  1308. FileStream outputStream = new FileStream("./Files/Payments/" + DateTime.Now.ToString("dd_MM_yyyy") + "/" + contract.id + "_" + contract.syntaxTelco + "_payment_" + contract.syntaxConpany + ".docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
  1309. document.Save(outputStream, FormatType.Docx);
  1310. document.Close();
  1311. outputStream.Flush();
  1312. outputStream.Dispose();
  1313. return true;
  1314. }
  1315. catch (Exception ex)
  1316. {
  1317. log.Error("Exp: " + ex);
  1318. }
  1319. return false;
  1320. }
  1321. public static bool InvoiceGTSDumpt(Contract contract)
  1322. {
  1323. try
  1324. {
  1325. string[] validformats = new[] { "MM/dd/yyyy", "yyyy/MM/dd", "MM/dd/yyyy HH:mm:ss", "dd-MMM-yyyy",
  1326. "MM/dd/yyyy hh:mm tt", "yyyy-MM-dd HH:mm:ss, fff", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss.fff", "yyyy-MM-dd"};
  1327. DateTime convertTime = DateTime.ParseExact(contract.time, validformats,
  1328. CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
  1329. // Creating a new document.
  1330. WordDocument document = new WordDocument();
  1331. // Setting document page margins.
  1332. MarginsF pagemargins = new MarginsF();
  1333. pagemargins.Bottom = 20;
  1334. pagemargins.Top = 20;
  1335. pagemargins.Left = 75;
  1336. pagemargins.Right = 75;
  1337. // Assigning document page margins to the current section.
  1338. IWSection section = document.AddSection();
  1339. section.PageSetup.Margins = pagemargins;
  1340. section.AddParagraph();
  1341. IWTable table = section.AddTable();
  1342. int rowNum = 1, columnNum = 2;
  1343. RowFormat format = new RowFormat();
  1344. table.ResetCells(rowNum, columnNum);
  1345. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  1346. for (int i = 0; i < columnNum; i++)
  1347. {
  1348. for (int j = 0; j < rowNum; j++)
  1349. {
  1350. WTableCell cell = table.Rows[j].Cells[i];
  1351. cell.Width = (float)(i == 0 ? table.Width * 0.65 : table.Width * 0.35);
  1352. cell.CellFormat.Paddings.Top = 5;
  1353. cell.CellFormat.Paddings.Bottom = 5;
  1354. cell.CellFormat.Paddings.Left = 5;
  1355. cell.CellFormat.Paddings.Right = 5;
  1356. cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
  1357. }
  1358. }
  1359. IWParagraph para = table[0, 0].AddParagraph();
  1360. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1361. IWTextRange textRange = para.AppendText(contract.company);
  1362. textRange.CharacterFormat.FontName = "Times New Roman";
  1363. textRange.CharacterFormat.FontSize = 12;
  1364. textRange.CharacterFormat.Bold = true;
  1365. para = table[0, 0].AddParagraph();
  1366. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1367. textRange = para.AppendText("Add: " + contract.address);
  1368. textRange.CharacterFormat.FontName = "Times New Roman";
  1369. textRange.CharacterFormat.FontSize = 12;
  1370. textRange.CharacterFormat.Bold = false;
  1371. para = table[0, 0].AddParagraph();
  1372. para = table[0, 0].AddParagraph();
  1373. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1374. textRange = para.AppendText("Registration Number: ");
  1375. textRange.CharacterFormat.FontName = "Times New Roman";
  1376. textRange.CharacterFormat.FontSize = 12;
  1377. textRange.CharacterFormat.Bold = true;
  1378. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1379. textRange = para.AppendText("0108079693");
  1380. textRange.CharacterFormat.FontName = "Times New Roman";
  1381. textRange.CharacterFormat.FontSize = 12;
  1382. textRange.CharacterFormat.Bold = false;
  1383. // Gets the image stream.
  1384. para = table[0, 1].AddParagraph();
  1385. FileStream imageStream = new FileStream("./resources/gts.jpg", FileMode.Open, FileAccess.Read);
  1386. IWPicture picture = para.AppendPicture(imageStream);
  1387. picture.TextWrappingStyle = TextWrappingStyle.InFrontOfText;
  1388. picture.VerticalOrigin = VerticalOrigin.Margin;
  1389. //picture.VerticalPosition = -45;
  1390. //picture.HorizontalOrigin = HorizontalOrigin.Column;
  1391. //picture.HorizontalPosition = 263.5f;
  1392. //picture.WidthScale = 20;
  1393. //picture.HeightScale = 15;
  1394. // content
  1395. //Appends paragraph.
  1396. IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();
  1397. paragraph = section.AddParagraph();
  1398. paragraph = section.AddParagraph();
  1399. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1400. textRange = paragraph.AppendText("INVOICE") as WTextRange;
  1401. textRange.CharacterFormat.FontSize = 25;
  1402. textRange.CharacterFormat.FontName = "Times New Roman";
  1403. textRange.CharacterFormat.Bold = true;
  1404. textRange.CharacterFormat.TextColor = Color.Orange;
  1405. paragraph = section.AddParagraph();
  1406. table = section.AddTable();
  1407. rowNum = 1; columnNum = 2;
  1408. table.ResetCells(rowNum, columnNum);
  1409. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  1410. float tableWidth = table.Width;
  1411. for (int i = 0; i < columnNum; i++)
  1412. {
  1413. for (int j = 0; j < rowNum; j++)
  1414. {
  1415. WTableCell cell = table.Rows[j].Cells[i];
  1416. cell.Width = (float)(i == 0 ? tableWidth * 0.5 : tableWidth * 0.5);
  1417. cell.CellFormat.Paddings.Top = 5;
  1418. cell.CellFormat.Paddings.Bottom = 5;
  1419. cell.CellFormat.Paddings.Left = 5;
  1420. cell.CellFormat.Paddings.Right = 5;
  1421. cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Dot;
  1422. }
  1423. }
  1424. para = table[0, 0].AddParagraph();
  1425. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1426. textRange = para.AppendText("No: ");
  1427. textRange.CharacterFormat.FontName = "Times New Roman";
  1428. textRange.CharacterFormat.FontSize = 15;
  1429. textRange.CharacterFormat.Bold = true;
  1430. textRange = para.AppendText(convertTime.ToString("ddMMyyyy") + "-" + contract.id);
  1431. textRange.CharacterFormat.FontName = "Times New Roman";
  1432. textRange.CharacterFormat.FontSize = 13;
  1433. textRange.CharacterFormat.Bold = false;
  1434. para = table[0, 1].AddParagraph();
  1435. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1436. textRange = para.AppendText("Date: ");
  1437. textRange.CharacterFormat.FontName = "Times New Roman";
  1438. textRange.CharacterFormat.FontSize = 15;
  1439. textRange.CharacterFormat.Bold = true;
  1440. textRange = para.AppendText(convertTime.ToString("dd/MM/yyyy"));
  1441. textRange.CharacterFormat.FontName = "Times New Roman";
  1442. textRange.CharacterFormat.FontSize = 13;
  1443. textRange.CharacterFormat.Bold = false;
  1444. paragraph = section.AddParagraph();
  1445. paragraph = section.AddParagraph();
  1446. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1447. textRange = paragraph.AppendText(contract.telco) as WTextRange;
  1448. textRange.CharacterFormat.FontSize = 12;
  1449. textRange.CharacterFormat.FontName = "Times New Roman";
  1450. textRange.CharacterFormat.Bold = true;
  1451. paragraph = section.AddParagraph();
  1452. paragraph = section.AddParagraph();
  1453. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1454. textRange = paragraph.AppendText("Address: ") as WTextRange;
  1455. textRange.CharacterFormat.FontSize = 12;
  1456. textRange.CharacterFormat.FontName = "Times New Roman";
  1457. textRange.CharacterFormat.Bold = true;
  1458. textRange = paragraph.AppendText("CBD 4 Timor Plaza, Comoro, Dili, Timor Leste") as WTextRange;
  1459. textRange.CharacterFormat.FontSize = 12;
  1460. textRange.CharacterFormat.FontName = "Times New Roman";
  1461. textRange.CharacterFormat.Bold = false;
  1462. paragraph = section.AddParagraph();
  1463. paragraph = section.AddParagraph();
  1464. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1465. textRange = paragraph.AppendText("Tax Registration No : ") as WTextRange;
  1466. textRange.CharacterFormat.FontSize = 12;
  1467. textRange.CharacterFormat.FontName = "Times New Roman";
  1468. textRange.CharacterFormat.Bold = true;
  1469. textRange = paragraph.AppendText("1150150") as WTextRange;
  1470. textRange.CharacterFormat.FontSize = 12;
  1471. textRange.CharacterFormat.FontName = "Times New Roman";
  1472. textRange.CharacterFormat.Bold = false;
  1473. paragraph = section.AddParagraph();
  1474. paragraph = section.AddParagraph();
  1475. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1476. textRange = paragraph.AppendText("Attention: ") as WTextRange;
  1477. textRange.CharacterFormat.FontSize = 12;
  1478. textRange.CharacterFormat.FontName = "Times New Roman";
  1479. textRange.CharacterFormat.Bold = true;
  1480. textRange = paragraph.AppendText("Mr. Tran Van Bang") as WTextRange;
  1481. textRange.CharacterFormat.FontSize = 12;
  1482. textRange.CharacterFormat.FontName = "Times New Roman";
  1483. textRange.CharacterFormat.Bold = false;
  1484. paragraph = section.AddParagraph();
  1485. paragraph = section.AddParagraph();
  1486. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1487. textRange = paragraph.AppendText("Contract: ") as WTextRange;
  1488. textRange.CharacterFormat.FontSize = 12;
  1489. textRange.CharacterFormat.FontName = "Times New Roman";
  1490. textRange.CharacterFormat.Bold = true;
  1491. textRange = paragraph.AppendText(contract.contractCode) as WTextRange;
  1492. textRange.CharacterFormat.FontSize = 12;
  1493. textRange.CharacterFormat.FontName = "Times New Roman";
  1494. textRange.CharacterFormat.Bold = false;
  1495. paragraph = section.AddParagraph();
  1496. table = section.AddTable();
  1497. rowNum = 2; columnNum = 3;
  1498. table.ResetCells(rowNum, columnNum);
  1499. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  1500. tableWidth = table.Width;
  1501. for (int i = 0; i < columnNum; i++)
  1502. {
  1503. for (int j = 0; j < rowNum; j++)
  1504. {
  1505. WTableCell cell = table.Rows[j].Cells[i];
  1506. cell.Width = (float)(i == 0 ? tableWidth * 0.1 : i == 1 ? tableWidth * 0.6 : tableWidth * 0.3);
  1507. cell.CellFormat.Paddings.Top = 5;
  1508. cell.CellFormat.Paddings.Bottom = 5;
  1509. cell.CellFormat.Paddings.Left = 5;
  1510. cell.CellFormat.Paddings.Right = 5;
  1511. cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Dot;
  1512. }
  1513. }
  1514. para = table[0, 0].AddParagraph();
  1515. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1516. textRange = para.AppendText("No");
  1517. textRange.CharacterFormat.FontName = "Times New Roman";
  1518. textRange.CharacterFormat.FontSize = 14;
  1519. textRange.CharacterFormat.Bold = true;
  1520. para = table[0, 1].AddParagraph();
  1521. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1522. textRange = para.AppendText("Description");
  1523. textRange.CharacterFormat.FontName = "Times New Roman";
  1524. textRange.CharacterFormat.FontSize = 14;
  1525. textRange.CharacterFormat.Bold = true;
  1526. para = table[0, 2].AddParagraph();
  1527. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1528. textRange = para.AppendText("Amount");
  1529. textRange.CharacterFormat.FontName = "Times New Roman";
  1530. textRange.CharacterFormat.FontSize = 14;
  1531. textRange.CharacterFormat.Bold = true;
  1532. para = table[1, 0].AddParagraph();
  1533. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1534. textRange = para.AppendText("1");
  1535. textRange.CharacterFormat.FontName = "Times New Roman";
  1536. textRange.CharacterFormat.FontSize = 12;
  1537. textRange.CharacterFormat.Bold = false;
  1538. para = table[1, 1].AddParagraph();
  1539. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1540. textRange = para.AppendText(contract.service + " service sharing revenue of " + convertTime.AddMonths(-1).ToString("MMMM yyyy"));
  1541. textRange.CharacterFormat.FontName = "Times New Roman";
  1542. textRange.CharacterFormat.FontSize = 14;
  1543. textRange.CharacterFormat.Bold = false;
  1544. para = table[1, 2].AddParagraph();
  1545. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1546. textRange = para.AppendText("USD " + int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
  1547. textRange.CharacterFormat.FontName = "Times New Roman";
  1548. textRange.CharacterFormat.FontSize = 14;
  1549. textRange.CharacterFormat.Bold = false;
  1550. paragraph = section.AddParagraph();
  1551. paragraph = section.AddParagraph();
  1552. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1553. textRange = paragraph.AppendText("In writing: " + ConvertAmount(double.Parse(contract.money)) + " dollars./.") as WTextRange;
  1554. textRange.CharacterFormat.FontSize = 12;
  1555. textRange.CharacterFormat.FontName = "Times New Roman";
  1556. textRange.CharacterFormat.Bold = true;
  1557. paragraph = section.AddParagraph();
  1558. paragraph = section.AddParagraph();
  1559. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1560. textRange = paragraph.AppendText("Following is the Payment reference:") as WTextRange;
  1561. textRange.CharacterFormat.FontSize = 12;
  1562. textRange.CharacterFormat.FontName = "Times New Roman";
  1563. textRange.CharacterFormat.Bold = true;
  1564. paragraph = section.AddParagraph();
  1565. paragraph = section.AddParagraph();
  1566. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1567. textRange = paragraph.AppendText("- Name of Bank: ") as WTextRange;
  1568. textRange.CharacterFormat.FontSize = 12;
  1569. textRange.CharacterFormat.FontName = "Times New Roman";
  1570. textRange.CharacterFormat.Bold = false;
  1571. textRange = paragraph.AppendText(contract.bank) as WTextRange;
  1572. textRange.CharacterFormat.FontSize = 12;
  1573. textRange.CharacterFormat.FontName = "Times New Roman";
  1574. textRange.CharacterFormat.Bold = false;
  1575. paragraph = section.AddParagraph();
  1576. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1577. textRange = paragraph.AppendText("- Address: ") as WTextRange;
  1578. textRange.CharacterFormat.FontSize = 12;
  1579. textRange.CharacterFormat.FontName = "Times New Roman";
  1580. textRange.CharacterFormat.Bold = false;
  1581. textRange = paragraph.AppendText(contract.address) as WTextRange;
  1582. textRange.CharacterFormat.FontSize = 12;
  1583. textRange.CharacterFormat.FontName = "Times New Roman";
  1584. textRange.CharacterFormat.Bold = false;
  1585. paragraph = section.AddParagraph();
  1586. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1587. textRange = paragraph.AppendText("- Swift Code: ") as WTextRange;
  1588. textRange.CharacterFormat.FontSize = 12;
  1589. textRange.CharacterFormat.FontName = "Times New Roman";
  1590. textRange.CharacterFormat.Bold = false;
  1591. textRange = paragraph.AppendText(contract.swiftCode) as WTextRange;
  1592. textRange.CharacterFormat.FontSize = 12;
  1593. textRange.CharacterFormat.FontName = "Times New Roman";
  1594. textRange.CharacterFormat.Bold = false;
  1595. paragraph = section.AddParagraph();
  1596. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1597. textRange = paragraph.AppendText("- Account No: ") as WTextRange;
  1598. textRange.CharacterFormat.FontSize = 12;
  1599. textRange.CharacterFormat.FontName = "Times New Roman";
  1600. textRange.CharacterFormat.Bold = false;
  1601. textRange = paragraph.AppendText(contract.account) as WTextRange;
  1602. textRange.CharacterFormat.FontSize = 12;
  1603. textRange.CharacterFormat.FontName = "Times New Roman";
  1604. textRange.CharacterFormat.Bold = false;
  1605. paragraph = section.AddParagraph();
  1606. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1607. textRange = paragraph.AppendText("- Account holdere: ") as WTextRange;
  1608. textRange.CharacterFormat.FontSize = 12;
  1609. textRange.CharacterFormat.FontName = "Times New Roman";
  1610. textRange.CharacterFormat.Bold = false;
  1611. textRange = paragraph.AppendText(contract.beneficiary) as WTextRange;
  1612. textRange.CharacterFormat.FontSize = 12;
  1613. textRange.CharacterFormat.FontName = "Times New Roman";
  1614. textRange.CharacterFormat.Bold = false;
  1615. table = section.AddTable();
  1616. rowNum = 1; columnNum = 2;
  1617. table.ResetCells(rowNum, columnNum);
  1618. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  1619. tableWidth = table.Width;
  1620. table.TableFormat.Borders.Color = Color.White;
  1621. for (int i = 0; i < columnNum; i++)
  1622. {
  1623. for (int j = 0; j < rowNum; j++)
  1624. {
  1625. WTableCell cell = table.Rows[j].Cells[i];
  1626. cell.Width = (float)(i == 0 ? tableWidth * 0.3 : tableWidth * 0.7);
  1627. cell.CellFormat.Paddings.Top = 5;
  1628. cell.CellFormat.Paddings.Bottom = 5;
  1629. cell.CellFormat.Paddings.Left = 5;
  1630. cell.CellFormat.Paddings.Right = 5;
  1631. cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
  1632. }
  1633. }
  1634. para = table[0, 1].AddParagraph();
  1635. para = table[0, 1].AddParagraph();
  1636. para = table[0, 1].AddParagraph();
  1637. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1638. textRange = para.AppendText("DIRECTOR");
  1639. textRange.CharacterFormat.FontName = "Times New Roman";
  1640. textRange.CharacterFormat.FontSize = 17;
  1641. textRange.CharacterFormat.Bold = true;
  1642. //Saves the Word document to MemoryStream
  1643. MemoryStream stream = new MemoryStream();
  1644. document.Save(stream, FormatType.Docx);
  1645. stream.Position = 0;
  1646. bool exists = System.IO.Directory.Exists("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
  1647. if (!exists)
  1648. System.IO.Directory.CreateDirectory("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
  1649. FileStream outputStream = new FileStream("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy") + "/" + contract.id + "_" + contract.syntaxTelco + "_invoice_" + contract.syntaxConpany + ".docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
  1650. document.Save(outputStream, FormatType.Docx);
  1651. document.Close();
  1652. outputStream.Flush();
  1653. outputStream.Dispose();
  1654. return true;
  1655. }
  1656. catch (Exception ex)
  1657. {
  1658. log.Error("Exp: " + ex);
  1659. return false;
  1660. }
  1661. }
  1662. public static bool InvoiceVTECHDumpt(Contract contract)
  1663. {
  1664. try
  1665. {
  1666. string[] validformats = new[] { "MM/dd/yyyy", "yyyy/MM/dd", "MM/dd/yyyy HH:mm:ss", "dd-MMM-yyyy",
  1667. "MM/dd/yyyy hh:mm tt", "yyyy-MM-dd HH:mm:ss, fff", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss.fff", "yyyy-MM-dd"};
  1668. DateTime convertTime = DateTime.ParseExact(contract.time, validformats,
  1669. CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
  1670. // Creating a new document.
  1671. WordDocument document = new WordDocument();
  1672. // Setting document page margins.
  1673. MarginsF pagemargins = new MarginsF();
  1674. pagemargins.Bottom = 20;
  1675. pagemargins.Top = 20;
  1676. pagemargins.Left = 75;
  1677. pagemargins.Right = 75;
  1678. // Assigning document page margins to the current section.
  1679. IWSection section = document.AddSection();
  1680. section.PageSetup.Margins = pagemargins;
  1681. section.AddParagraph();
  1682. IWTable table = section.AddTable();
  1683. int rowNum = 7, columnNum = 2;
  1684. RowFormat format = new RowFormat();
  1685. table.ResetCells(rowNum, columnNum);
  1686. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  1687. float tableWidth = table.Width;
  1688. //table.TableFormat.BackColor = Color.FromArgb(192, 192, 192);
  1689. table.Rows[0].Cells[0].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
  1690. table.Rows[0].Cells[1].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
  1691. table.Rows[2].Cells[0].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
  1692. table.Rows[2].Cells[1].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
  1693. table.Rows[4].Cells[0].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
  1694. table.Rows[4].Cells[1].CellFormat.BackColor = Color.FromArgb(156, 194, 229);
  1695. for (int i = 0; i < columnNum; i++)
  1696. {
  1697. for (int j = 0; j < rowNum; j++)
  1698. {
  1699. WTableCell cell = table.Rows[j].Cells[i];
  1700. cell.Width = (float)(i == 0 ? tableWidth * 0.5 : tableWidth * 0.5);
  1701. cell.CellFormat.Paddings.Top = 5;
  1702. cell.CellFormat.Paddings.Bottom = 5;
  1703. cell.CellFormat.Paddings.Left = 5;
  1704. cell.CellFormat.Paddings.Right = 5;
  1705. if (i == 0)
  1706. {
  1707. if (j == 6)
  1708. {
  1709. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  1710. cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
  1711. cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
  1712. cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
  1713. }
  1714. else if (j == 1 || j == 2 || j == 5 || j == 4)
  1715. {
  1716. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  1717. cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
  1718. cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
  1719. }
  1720. else
  1721. {
  1722. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  1723. cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
  1724. }
  1725. }
  1726. else if (i == 1)
  1727. {
  1728. if (j == 6)
  1729. {
  1730. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  1731. cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
  1732. cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
  1733. }
  1734. else if (j == 1 || j == 2 || j == 5 || j == 4)
  1735. {
  1736. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  1737. cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
  1738. cell.CellFormat.Borders.Left.BorderType = BorderStyle.Single;
  1739. }
  1740. else
  1741. {
  1742. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  1743. }
  1744. }
  1745. }
  1746. }
  1747. table.ApplyHorizontalMerge(0, 0, 1);
  1748. IWParagraph para = table[0, 0].AddParagraph();
  1749. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1750. IWTextRange textRange = para.AppendText("COMMERCIAL INVOICE");
  1751. textRange.CharacterFormat.FontName = "Times New Roman";
  1752. textRange.CharacterFormat.FontSize = 16;
  1753. textRange.CharacterFormat.Bold = true;
  1754. para = table[0, 0].AddParagraph();
  1755. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1756. textRange = para.AppendText("No: " + convertTime.ToString("ddMMyyyy") + "-" + contract.id);
  1757. textRange.CharacterFormat.FontName = "Times New Roman";
  1758. textRange.CharacterFormat.FontSize = 13;
  1759. textRange.CharacterFormat.Bold = true;
  1760. para = table[0, 0].AddParagraph();
  1761. para = table[1, 0].AddParagraph();
  1762. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1763. textRange = para.AppendText("DATE OF EXPORT");
  1764. textRange.CharacterFormat.FontName = "Times New Roman";
  1765. textRange.CharacterFormat.FontSize = 11;
  1766. textRange.CharacterFormat.Bold = true;
  1767. para = table[1, 0].AddParagraph();
  1768. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1769. textRange = para.AppendText(convertTime.ToString("dd/MM/yyyy"));
  1770. textRange.CharacterFormat.FontName = "Times New Roman";
  1771. textRange.CharacterFormat.FontSize = 11;
  1772. textRange.CharacterFormat.Bold = false;
  1773. para = table[1, 0].AddParagraph();
  1774. para = table[1, 1].AddParagraph();
  1775. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1776. textRange = para.AppendText("CONTRACT");
  1777. textRange.CharacterFormat.FontName = "Times New Roman";
  1778. textRange.CharacterFormat.FontSize = 11;
  1779. textRange.CharacterFormat.Bold = true;
  1780. para = table[1, 1].AddParagraph();
  1781. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1782. //String d1 = (int.Parse(contract.id) < 10 ? "0" + contract.id : contract.id) + "/VTL-" + contract.syntaxConpany + "/VAS/" + convertTime.ToString("yyyy");
  1783. String d1 = contract.contractCode;
  1784. textRange = para.AppendText(d1);
  1785. textRange.CharacterFormat.FontName = "Times New Roman";
  1786. textRange.CharacterFormat.FontSize = 11;
  1787. textRange.CharacterFormat.Bold = false;
  1788. para = table[1, 1].AddParagraph();
  1789. para = table[2, 0].AddParagraph();
  1790. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1791. textRange = para.AppendText("PROVIDER");
  1792. textRange.CharacterFormat.FontName = "Times New Roman";
  1793. textRange.CharacterFormat.FontSize = 11;
  1794. textRange.CharacterFormat.Bold = true;
  1795. para = table[2, 1].AddParagraph();
  1796. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1797. textRange = para.AppendText("BUYER");
  1798. textRange.CharacterFormat.FontName = "Times New Roman";
  1799. textRange.CharacterFormat.FontSize = 11;
  1800. textRange.CharacterFormat.Bold = true;
  1801. para = table[3, 0].AddParagraph();
  1802. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1803. textRange = para.AppendText("NAME: " + contract.company);
  1804. textRange.CharacterFormat.FontName = "Times New Roman";
  1805. textRange.CharacterFormat.FontSize = 11;
  1806. textRange.CharacterFormat.Bold = false;
  1807. para = table[3, 0].AddParagraph();
  1808. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1809. textRange = para.AppendText("Address: " + contract.address);
  1810. textRange.CharacterFormat.FontName = "Times New Roman";
  1811. textRange.CharacterFormat.FontSize = 11;
  1812. textRange.CharacterFormat.Bold = false;
  1813. para = table[3, 0].AddParagraph();
  1814. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1815. textRange = para.AppendText("Tax code: " + "0108453894");
  1816. textRange.CharacterFormat.FontName = "Times New Roman";
  1817. textRange.CharacterFormat.FontSize = 11;
  1818. textRange.CharacterFormat.Bold = false;
  1819. para = table[3, 0].AddParagraph();
  1820. para = table[3, 1].AddParagraph();
  1821. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1822. textRange = para.AppendText("NAME: " + contract.telco);
  1823. textRange.CharacterFormat.FontName = "Times New Roman";
  1824. textRange.CharacterFormat.FontSize = 11;
  1825. textRange.CharacterFormat.Bold = false;
  1826. para = table[3, 1].AddParagraph();
  1827. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1828. textRange = para.AppendText("Address: " + contract.addressTelco + ".");
  1829. textRange.CharacterFormat.FontName = "Times New Roman";
  1830. textRange.CharacterFormat.FontSize = 11;
  1831. textRange.CharacterFormat.Bold = false;
  1832. para = table[3, 1].AddParagraph();
  1833. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1834. textRange = para.AppendText("Tax code: " + "1150150");
  1835. textRange.CharacterFormat.FontName = "Times New Roman";
  1836. textRange.CharacterFormat.FontSize = 11;
  1837. textRange.CharacterFormat.Bold = false;
  1838. para = table[3, 1].AddParagraph();
  1839. para = table[4, 0].AddParagraph();
  1840. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  1841. textRange = para.AppendText("DEFINITION OF PAYMENT");
  1842. textRange.CharacterFormat.FontName = "Times New Roman";
  1843. textRange.CharacterFormat.FontSize = 11;
  1844. textRange.CharacterFormat.Bold = true;
  1845. IWTable table2 = table[4, 1].AddTable();
  1846. rowNum = 1; columnNum = 3;
  1847. table2.ResetCells(rowNum, columnNum);
  1848. table2.TableFormat.HorizontalAlignment = RowAlignment.Center;
  1849. tableWidth = table2.Width;
  1850. for (int i = 0; i < columnNum; i++)
  1851. {
  1852. for (int j = 0; j < rowNum; j++)
  1853. {
  1854. WTableCell cell = table2.Rows[j].Cells[i];
  1855. if (i == 1)
  1856. {
  1857. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  1858. cell.CellFormat.Borders.Left.BorderType = BorderStyle.Single;
  1859. cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
  1860. }
  1861. else
  1862. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  1863. }
  1864. }
  1865. IWParagraph para2 = table2[0, 0].AddParagraph();
  1866. para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1867. textRange = para2.AppendText("QUANTITY");
  1868. textRange.CharacterFormat.FontName = "Times New Roman";
  1869. textRange.CharacterFormat.FontSize = 10;
  1870. textRange.CharacterFormat.Bold = true;
  1871. para2 = table2[0, 1].AddParagraph();
  1872. para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1873. textRange = para2.AppendText("UNIT PRICE (USD)");
  1874. textRange.CharacterFormat.FontName = "Times New Roman";
  1875. textRange.CharacterFormat.FontSize = 10;
  1876. textRange.CharacterFormat.Bold = true;
  1877. para2 = table2[0, 2].AddParagraph();
  1878. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1879. textRange = para2.AppendText("TOTAL (USD)");
  1880. textRange.CharacterFormat.FontName = "Times New Roman";
  1881. textRange.CharacterFormat.FontSize = 10;
  1882. textRange.CharacterFormat.Bold = true;
  1883. //
  1884. para = table[5, 0].AddParagraph();
  1885. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1886. textRange = para.AppendText(contract.service + " service sharing revenue of " + convertTime.AddMonths(-1).ToString("MMMM yyyy"));
  1887. textRange.CharacterFormat.FontName = "Times New Roman";
  1888. textRange.CharacterFormat.FontSize = 11;
  1889. textRange.CharacterFormat.Bold = false;
  1890. para = table[5, 0].AddParagraph();
  1891. table2 = table[5, 1].AddTable();
  1892. rowNum = 1; columnNum = 3;
  1893. table2.ResetCells(rowNum, columnNum);
  1894. table2.TableFormat.HorizontalAlignment = RowAlignment.Center;
  1895. tableWidth = table2.Width;
  1896. for (int i = 0; i < columnNum; i++)
  1897. {
  1898. for (int j = 0; j < rowNum; j++)
  1899. {
  1900. WTableCell cell = table2.Rows[j].Cells[i];
  1901. cell.CellFormat.Paddings.Top = 5;
  1902. cell.CellFormat.Paddings.Bottom = 5;
  1903. cell.CellFormat.Paddings.Left = 5;
  1904. cell.CellFormat.Paddings.Right = 5;
  1905. if (i == 1)
  1906. {
  1907. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  1908. cell.CellFormat.Borders.Left.BorderType = BorderStyle.Single;
  1909. cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
  1910. }
  1911. else
  1912. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  1913. }
  1914. }
  1915. para2 = table2[0, 0].AddParagraph();
  1916. para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1917. textRange = para2.AppendText("1");
  1918. textRange.CharacterFormat.FontName = "Times New Roman";
  1919. textRange.CharacterFormat.FontSize = 11;
  1920. textRange.CharacterFormat.Bold = false;
  1921. para2 = table2[0, 0].AddParagraph();
  1922. para2 = table2[0, 0].AddParagraph();
  1923. para2 = table2[0, 1].AddParagraph();
  1924. para2.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1925. textRange = para2.AppendText(int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
  1926. textRange.CharacterFormat.FontName = "Times New Roman";
  1927. textRange.CharacterFormat.FontSize = 11;
  1928. textRange.CharacterFormat.Bold = false;
  1929. para2 = table2[0, 1].AddParagraph();
  1930. para2 = table2[0, 1].AddParagraph();
  1931. para2 = table2[0, 2].AddParagraph();
  1932. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1933. textRange = para2.AppendText(int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
  1934. textRange.CharacterFormat.FontName = "Times New Roman";
  1935. textRange.CharacterFormat.FontSize = 11;
  1936. textRange.CharacterFormat.Bold = false;
  1937. para2 = table2[0, 2].AddParagraph();
  1938. para2 = table2[0, 2].AddParagraph();
  1939. para = table[6, 0].AddParagraph();
  1940. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1941. textRange = para.AppendText("TOTAL");
  1942. textRange.CharacterFormat.FontName = "Times New Roman";
  1943. textRange.CharacterFormat.FontSize = 12;
  1944. textRange.CharacterFormat.Bold = true;
  1945. para = table[6, 0].AddParagraph();
  1946. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1947. textRange = para.AppendText("By word:");
  1948. textRange.CharacterFormat.FontName = "Times New Roman";
  1949. textRange.CharacterFormat.FontSize = 11;
  1950. textRange.CharacterFormat.Bold = true;
  1951. para = table[6, 1].AddParagraph();
  1952. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Right;
  1953. textRange = para.AppendText(int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture));
  1954. textRange.CharacterFormat.FontName = "Times New Roman";
  1955. textRange.CharacterFormat.FontSize = 11;
  1956. textRange.CharacterFormat.Bold = true;
  1957. para = table[6, 1].AddParagraph();
  1958. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1959. textRange = para.AppendText(ConvertAmount(double.Parse(contract.money)) + " Dollars.");
  1960. textRange.CharacterFormat.FontName = "Times New Roman";
  1961. textRange.CharacterFormat.FontSize = 11;
  1962. textRange.CharacterFormat.Bold = true;
  1963. // content
  1964. //Appends paragraph.
  1965. IWParagraph paragraph = section.HeadersFooters.Header.AddParagraph();
  1966. paragraph = section.AddParagraph();
  1967. paragraph = section.AddParagraph();
  1968. paragraph.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  1969. textRange = paragraph.AppendText("Please remit payment to:") as WTextRange;
  1970. textRange.CharacterFormat.FontSize = 11;
  1971. textRange.CharacterFormat.FontName = "Times New Roman";
  1972. textRange.CharacterFormat.Bold = true;
  1973. paragraph = section.AddParagraph();
  1974. table = section.AddTable();
  1975. rowNum = 5; columnNum = 2;
  1976. table.ResetCells(rowNum, columnNum);
  1977. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  1978. tableWidth = table.Width;
  1979. for (int i = 0; i < columnNum; i++)
  1980. {
  1981. for (int j = 0; j < rowNum; j++)
  1982. {
  1983. WTableCell cell = table.Rows[j].Cells[i];
  1984. cell.Width = (float)(i == 0 ? tableWidth * 0.3 : tableWidth * 0.7);
  1985. cell.CellFormat.Paddings.Top = 5;
  1986. cell.CellFormat.Paddings.Bottom = 5;
  1987. cell.CellFormat.Paddings.Left = 5;
  1988. cell.CellFormat.Paddings.Right = 5;
  1989. if (i == 0)
  1990. {
  1991. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  1992. cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
  1993. cell.CellFormat.Borders.Right.BorderType = BorderStyle.Single;
  1994. cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
  1995. }
  1996. else if (i == 1)
  1997. {
  1998. cell.CellFormat.Borders.BorderType = BorderStyle.Cleared;
  1999. cell.CellFormat.Borders.Top.BorderType = BorderStyle.Single;
  2000. cell.CellFormat.Borders.Bottom.BorderType = BorderStyle.Single;
  2001. }
  2002. }
  2003. }
  2004. para = table[0, 0].AddParagraph();
  2005. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  2006. textRange = para.AppendText("Name of Beneficiary");
  2007. textRange.CharacterFormat.FontName = "Times New Roman";
  2008. textRange.CharacterFormat.FontSize = 11;
  2009. textRange.CharacterFormat.Bold = false;
  2010. para = table[0, 1].AddParagraph();
  2011. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  2012. textRange = para.AppendText(contract.beneficiary);
  2013. textRange.CharacterFormat.FontName = "Times New Roman";
  2014. textRange.CharacterFormat.FontSize = 11;
  2015. textRange.CharacterFormat.Bold = false;
  2016. para = table[1, 0].AddParagraph();
  2017. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  2018. textRange = para.AppendText("Address");
  2019. textRange.CharacterFormat.FontName = "Times New Roman";
  2020. textRange.CharacterFormat.FontSize = 11;
  2021. textRange.CharacterFormat.Bold = false;
  2022. para = table[1, 1].AddParagraph();
  2023. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  2024. textRange = para.AppendText(contract.address);
  2025. textRange.CharacterFormat.FontName = "Times New Roman";
  2026. textRange.CharacterFormat.FontSize = 11;
  2027. textRange.CharacterFormat.Bold = false;
  2028. para = table[2, 0].AddParagraph();
  2029. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  2030. textRange = para.AppendText("Name of Beneficiary’s bank");
  2031. textRange.CharacterFormat.FontName = "Times New Roman";
  2032. textRange.CharacterFormat.FontSize = 11;
  2033. textRange.CharacterFormat.Bold = false;
  2034. para = table[2, 1].AddParagraph();
  2035. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  2036. textRange = para.AppendText(contract.bank);
  2037. textRange.CharacterFormat.FontName = "Times New Roman";
  2038. textRange.CharacterFormat.FontSize = 11;
  2039. textRange.CharacterFormat.Bold = false;
  2040. para = table[3, 0].AddParagraph();
  2041. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  2042. textRange = para.AppendText("Account number");
  2043. textRange.CharacterFormat.FontName = "Times New Roman";
  2044. textRange.CharacterFormat.FontSize = 11;
  2045. textRange.CharacterFormat.Bold = false;
  2046. para = table[3, 1].AddParagraph();
  2047. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  2048. textRange = para.AppendText(contract.account);
  2049. textRange.CharacterFormat.FontName = "Times New Roman";
  2050. textRange.CharacterFormat.FontSize = 11;
  2051. textRange.CharacterFormat.Bold = false;
  2052. para = table[4, 0].AddParagraph();
  2053. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  2054. textRange = para.AppendText("SWIFT Code");
  2055. textRange.CharacterFormat.FontName = "Times New Roman";
  2056. textRange.CharacterFormat.FontSize = 11;
  2057. textRange.CharacterFormat.Bold = false;
  2058. para = table[4, 1].AddParagraph();
  2059. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Left;
  2060. textRange = para.AppendText(contract.swiftCode);
  2061. textRange.CharacterFormat.FontName = "Times New Roman";
  2062. textRange.CharacterFormat.FontSize = 11;
  2063. textRange.CharacterFormat.Bold = false;
  2064. paragraph = section.AddParagraph();
  2065. table = section.AddTable();
  2066. rowNum = 1; columnNum = 2;
  2067. table.ResetCells(rowNum, columnNum);
  2068. table.TableFormat.HorizontalAlignment = RowAlignment.Center;
  2069. tableWidth = table.Width;
  2070. table.TableFormat.Borders.Color = Color.White;
  2071. for (int i = 0; i < columnNum; i++)
  2072. {
  2073. for (int j = 0; j < rowNum; j++)
  2074. {
  2075. WTableCell cell = table.Rows[j].Cells[i];
  2076. cell.Width = (float)(i == 0 ? tableWidth * 0.6 : tableWidth * 0.4);
  2077. cell.CellFormat.Paddings.Top = 5;
  2078. cell.CellFormat.Paddings.Bottom = 5;
  2079. cell.CellFormat.Paddings.Left = 5;
  2080. cell.CellFormat.Paddings.Right = 5;
  2081. cell.CellFormat.Borders.BorderType = Syncfusion.DocIO.DLS.BorderStyle.Cleared;
  2082. }
  2083. }
  2084. para = table[0, 1].AddParagraph();
  2085. para.ParagraphFormat.HorizontalAlignment = HorizontalAlignment.Center;
  2086. textRange = para.AppendText("SIGNATURE");
  2087. textRange.CharacterFormat.FontName = "Times New Roman";
  2088. textRange.CharacterFormat.FontSize = 11;
  2089. textRange.CharacterFormat.Bold = true;
  2090. //Saves the Word document to MemoryStream
  2091. MemoryStream stream = new MemoryStream();
  2092. document.Save(stream, FormatType.Docx);
  2093. stream.Position = 0;
  2094. bool exists = System.IO.Directory.Exists("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
  2095. if (!exists)
  2096. System.IO.Directory.CreateDirectory("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
  2097. FileStream outputStream = new FileStream("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy") + "/" + contract.id + "_" + contract.syntaxTelco + "_invoice_" + contract.syntaxConpany + ".docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
  2098. document.Save(outputStream, FormatType.Docx);
  2099. document.Close();
  2100. outputStream.Flush();
  2101. outputStream.Dispose();
  2102. return true;
  2103. }
  2104. catch (Exception ex)
  2105. {
  2106. log.Error("Exp: " + ex);
  2107. return false;
  2108. }
  2109. }
  2110. public static bool InvoiceITLDumpt(Contract contract)
  2111. {
  2112. try
  2113. {
  2114. string[] validformats = new[] { "MM/dd/yyyy", "yyyy/MM/dd", "MM/dd/yyyy HH:mm:ss", "dd-MMM-yyyy",
  2115. "MM/dd/yyyy hh:mm tt", "yyyy-MM-dd HH:mm:ss, fff", "yyyy-MM-ddTHH:mm:ss", "yyyy-MM-ddTHH:mm", "yyyy-MM-ddTHH:mm:ss.fff", "yyyy-MM-dd"};
  2116. DateTime convertTime = DateTime.ParseExact(contract.time, validformats,
  2117. CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
  2118. ExcelEngine excelEngine = new ExcelEngine();
  2119. int rowCount = 1;
  2120. IApplication application = excelEngine.Excel;
  2121. application.DefaultVersion = ExcelVersion.Excel2013;
  2122. IWorkbook workbook = application.Workbooks.Create(1);
  2123. IWorksheet worksheet = workbook.Worksheets[0];
  2124. List<RowAttributed> rowAttributedList = new List<RowAttributed>();
  2125. worksheet.Range["A1"].ColumnWidth = 3;
  2126. worksheet.Range["B1"].ColumnWidth = 50;
  2127. worksheet.Range["C1"].ColumnWidth = 8;
  2128. worksheet.Range["D1"].ColumnWidth = 14;
  2129. worksheet.Range["E1"].ColumnWidth = 18;
  2130. worksheet.Range["F1"].ColumnWidth = 30;
  2131. //Defining body style
  2132. Syncfusion.XlsIO.IStyle bodyStyle = workbook.Styles.Add("BodyStyle");
  2133. bodyStyle.BeginUpdate();
  2134. bodyStyle.Color = Color.FromArgb(255, 255, 255);
  2135. bodyStyle.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.None;
  2136. bodyStyle.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.None;
  2137. bodyStyle.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.None;
  2138. bodyStyle.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.None;
  2139. bodyStyle.EndUpdate();
  2140. worksheet.Range["A1:F39"].CellStyle = bodyStyle;
  2141. // style
  2142. Syncfusion.XlsIO.IStyle cellStyleTableCenterBold = workbook.Styles.Add("table-center-bold");
  2143. cellStyleTableCenterBold.Font.Size = 12;
  2144. cellStyleTableCenterBold.Font.Bold = true;
  2145. cellStyleTableCenterBold.Font.FontName = "Roboto";
  2146. cellStyleTableCenterBold.HorizontalAlignment = ExcelHAlign.HAlignCenter;
  2147. cellStyleTableCenterBold.VerticalAlignment = ExcelVAlign.VAlignCenter;
  2148. cellStyleTableCenterBold.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin;
  2149. cellStyleTableCenterBold.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
  2150. cellStyleTableCenterBold.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.Thin;
  2151. cellStyleTableCenterBold.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.Thin;
  2152. Syncfusion.XlsIO.IStyle cellStyleTableCenterNormal = workbook.Styles.Add("table-center-normal");
  2153. cellStyleTableCenterNormal.Font.Size = 12;
  2154. cellStyleTableCenterNormal.Font.Bold = false;
  2155. cellStyleTableCenterNormal.Font.FontName = "Roboto";
  2156. cellStyleTableCenterNormal.HorizontalAlignment = ExcelHAlign.HAlignCenter;
  2157. cellStyleTableCenterNormal.VerticalAlignment = ExcelVAlign.VAlignCenter;
  2158. cellStyleTableCenterNormal.Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin;
  2159. cellStyleTableCenterNormal.Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
  2160. cellStyleTableCenterNormal.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.Thin;
  2161. cellStyleTableCenterNormal.Borders[ExcelBordersIndex.EdgeRight].LineStyle = ExcelLineStyle.Thin;
  2162. Syncfusion.XlsIO.IStyle cellStyleTextBold = workbook.Styles.Add("text-bold");
  2163. cellStyleTextBold.Font.Size = 12;
  2164. cellStyleTextBold.Font.Bold = true;
  2165. cellStyleTextBold.Font.FontName = "Roboto";
  2166. Syncfusion.XlsIO.IStyle cellStyleTextBoldCenter = workbook.Styles.Add("text-bold-center");
  2167. cellStyleTextBoldCenter.Font.Size = 12;
  2168. cellStyleTextBoldCenter.Font.Bold = true;
  2169. cellStyleTextBoldCenter.HorizontalAlignment = ExcelHAlign.HAlignCenter;
  2170. cellStyleTextBoldCenter.Font.FontName = "Roboto";
  2171. Syncfusion.XlsIO.IStyle cellStyleTextNormal = workbook.Styles.Add("text-normal");
  2172. cellStyleTextNormal.Font.Size = 12;
  2173. cellStyleTextNormal.Font.Bold = false;
  2174. cellStyleTextNormal.Font.FontName = "Roboto";
  2175. Syncfusion.XlsIO.IStyle cellStyleTextNormalCenter = workbook.Styles.Add("text-normal-center");
  2176. cellStyleTextNormalCenter.Font.Size = 12;
  2177. cellStyleTextNormalCenter.Font.Bold = false;
  2178. cellStyleTextNormalCenter.HorizontalAlignment = ExcelHAlign.HAlignCenter;
  2179. cellStyleTextNormalCenter.Font.FontName = "Roboto";
  2180. worksheet.Range[GetExcelColumnName(1) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].Merge();
  2181. Syncfusion.XlsIO.IStyle rowStyle = workbook.Styles.Add("style1");
  2182. rowStyle.Borders[ExcelBordersIndex.EdgeLeft].LineStyle = ExcelLineStyle.None;
  2183. rowStyle.Color = Color.FromArgb(255, 174, 33);
  2184. worksheet.Range[GetExcelColumnName(1) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].CellStyle = rowStyle;
  2185. rowCount++;
  2186. worksheet.Range[GetExcelColumnName(1) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].Merge();
  2187. rowStyle = workbook.Styles.Add("style2");
  2188. rowStyle.Color = Color.FromArgb(255, 0, 0);
  2189. worksheet.Range[GetExcelColumnName(1) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].CellStyle = rowStyle;
  2190. worksheet.Range[GetExcelColumnName(1) + 39.ToString() + ":" + GetExcelColumnName(6) + 39.ToString()].CellStyle = rowStyle;
  2191. rowCount++;
  2192. rowCount++;
  2193. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "INVOICE";
  2194. Syncfusion.XlsIO.IStyle cellStyle = workbook.Styles.Add("style3");
  2195. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].RowHeight = 120;
  2196. cellStyle.Font.Size = 24;
  2197. cellStyle.Font.Bold = true;
  2198. cellStyle.VerticalAlignment = ExcelVAlign.VAlignCenter;
  2199. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyle;
  2200. //Adding a picture
  2201. FileStream imageStream = new FileStream("./resources/ITL.jpg", FileMode.Open, FileAccess.Read);
  2202. IPictureShape shape = worksheet.Pictures.AddPicture(6, 3, imageStream);
  2203. //Positioning a Picture
  2204. shape.Top = 60;
  2205. shape.Left = 700;
  2206. //Re-sizing a Picture
  2207. shape.Height = 160;
  2208. shape.Width = 180;
  2209. rowCount++;
  2210. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(5) + rowCount.ToString()].Merge();
  2211. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = contract.company;
  2212. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextBold;
  2213. worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].Text = convertTime.ToString("dd/MM/yyyy");
  2214. worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].CellStyle = cellStyleTextBoldCenter;
  2215. rowCount++;
  2216. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(5) + rowCount.ToString()].Merge();
  2217. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = contract.address;
  2218. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
  2219. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].RowHeight = 40;
  2220. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].WrapText = true;
  2221. worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].Text = "INVOICE No." + convertTime.ToString("yyyyMMdd") + "-" + contract.id;
  2222. worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].CellStyle = cellStyleTextBoldCenter;
  2223. worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].Borders[ExcelBordersIndex.EdgeTop].LineStyle = ExcelLineStyle.Thin;
  2224. worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
  2225. rowCount++;
  2226. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(5) + rowCount.ToString()].Merge();
  2227. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "Tax Code: 0107836502";
  2228. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
  2229. rowCount++;
  2230. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "Email: vninterland@gmail.com";
  2231. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
  2232. rowCount += 3;
  2233. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "BILL TO";
  2234. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextBold;
  2235. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
  2236. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Borders[ExcelBordersIndex.EdgeBottom].ColorRGB = Color.FromArgb(215, 215, 215);
  2237. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].Borders[ExcelBordersIndex.EdgeBottom].LineStyle = ExcelLineStyle.Thin;
  2238. rowCount += 3;
  2239. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = contract.telco;
  2240. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextBold;
  2241. rowCount++;
  2242. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = contract.addressTelco;
  2243. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
  2244. rowCount++;
  2245. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "Tel: +670 76900005";
  2246. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
  2247. rowCount++;
  2248. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "Tax code: 1150150";
  2249. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
  2250. rowCount ++;
  2251. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = contract.contractCode;
  2252. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle = cellStyleTextNormal;
  2253. rowCount += 2;
  2254. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(3) + rowCount.ToString()].Merge();
  2255. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "DESCRIPTION";
  2256. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(3) + rowCount.ToString()].CellStyle = cellStyleTableCenterBold;
  2257. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].CellStyle.Font.Size = 11;
  2258. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].Text = "QTY";
  2259. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].CellStyle = cellStyleTableCenterBold;
  2260. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].CellStyle.Font.Size = 11;
  2261. worksheet.Range[GetExcelColumnName(5) + rowCount.ToString()].Text = "UNIT PRICE (USD)";
  2262. worksheet.Range[GetExcelColumnName(5) + rowCount.ToString()].CellStyle = cellStyleTableCenterBold;
  2263. worksheet.Range[GetExcelColumnName(5) + rowCount.ToString()].CellStyle.Font.Size = 11;
  2264. worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].Text = "TOTAL (USD)";
  2265. worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].CellStyle = cellStyleTableCenterBold;
  2266. worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].CellStyle.Font.Size = 11;
  2267. rowCount++;
  2268. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(3) + rowCount.ToString()].Merge();
  2269. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(2) + (rowCount + 1).ToString()].Merge();
  2270. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = contract.service + " service sharing revenue of " + convertTime.AddMonths(-1).ToString("MMMM yyyy");
  2271. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(3) + rowCount.ToString()].CellStyle = cellStyleTableCenterNormal;
  2272. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(2) + (rowCount + 1).ToString()].CellStyle = cellStyleTableCenterNormal;
  2273. worksheet.Range[GetExcelColumnName(3) + rowCount.ToString() + ":" + GetExcelColumnName(3) + (rowCount + 1).ToString()].CellStyle = cellStyleTableCenterNormal;
  2274. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].Text = "1";
  2275. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString() + ":" + GetExcelColumnName(4) + (rowCount + 1).ToString()].Merge();
  2276. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].CellStyle = cellStyleTableCenterNormal;
  2277. worksheet.Range[GetExcelColumnName(5) + rowCount.ToString() + ":" + GetExcelColumnName(5) + (rowCount + 1).ToString()].Merge();
  2278. worksheet.Range[GetExcelColumnName(5) + rowCount.ToString()].Text = int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture);
  2279. worksheet.Range[GetExcelColumnName(5) + rowCount.ToString() + ":" + GetExcelColumnName(5) + (rowCount + 1).ToString()].CellStyle = cellStyleTableCenterNormal;
  2280. worksheet.Range[GetExcelColumnName(6) + rowCount.ToString() + ":" + GetExcelColumnName(6) + (rowCount + 1).ToString()].Merge();
  2281. worksheet.Range[GetExcelColumnName(6) + rowCount.ToString()].Text = int.Parse(contract.money).ToString("0,0", CultureInfo.InvariantCulture);
  2282. worksheet.Range[GetExcelColumnName(6) + rowCount.ToString() + ":" + GetExcelColumnName(6) + (rowCount + 1).ToString()].CellStyle = cellStyleTableCenterBold;
  2283. rowCount += 2;
  2284. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].Merge();
  2285. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString()].Text = "By word: " + ConvertAmount(double.Parse(contract.money)) + " USD.";
  2286. worksheet.Range[GetExcelColumnName(2) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].CellStyle = cellStyleTableCenterNormal;
  2287. rowCount += 2;
  2288. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].Merge();
  2289. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].Text = contract.company;
  2290. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].CellStyle = cellStyleTextBoldCenter;
  2291. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].CellStyle.Font.Size = 11;
  2292. rowCount++;
  2293. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].Merge();
  2294. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].Text = "DIRECTOR";
  2295. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString() + ":" + GetExcelColumnName(6) + rowCount.ToString()].CellStyle = cellStyleTextBoldCenter;
  2296. worksheet.Range[GetExcelColumnName(4) + rowCount.ToString()].CellStyle.Font.Size = 11;
  2297. rowCount++;
  2298. //Saving the workbook as stream
  2299. bool exists = System.IO.Directory.Exists("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
  2300. if (!exists)
  2301. System.IO.Directory.CreateDirectory("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy"));
  2302. FileStream stream = new FileStream("./Files/Invoices/" + DateTime.Now.ToString("dd_MM_yyyy") + "/" + contract.id + "_" + contract.syntaxTelco + "_invoice_" + contract.syntaxConpany + ".xlsx", FileMode.Create, FileAccess.ReadWrite);
  2303. workbook.SaveAs(stream);
  2304. stream.Dispose();
  2305. return true;
  2306. }
  2307. catch (Exception ex)
  2308. {
  2309. log.Error("Exp: " + ex);
  2310. return false;
  2311. }
  2312. }
  2313. private static String[] units = { "Zero", "One", "Two", "Three",
  2314. "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven",
  2315. "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen",
  2316. "Seventeen", "Eighteen", "Nineteen" };
  2317. private static String[] unitsNormal = { "zero", "one", "two", "three",
  2318. "four", "five", "six", "seven", "eight", "nine", "ten", "eleven",
  2319. "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
  2320. "seventeen", "eighteen", "nineteen" };
  2321. private static String[] tens = { "", "", "Twenty", "Thirty", "Forty",
  2322. "Fifty", "Sixty", "Seventy", "Eighty", "Ninety" };
  2323. private static String[] tensNormal = { "", "", "twenty", "thirty", "forty",
  2324. "fifty", "sixty", "seventy", "eighty", "ninety" };
  2325. public static String ConvertAmount(double amount)
  2326. {
  2327. try
  2328. {
  2329. Int64 amount_int = (Int64)amount;
  2330. Int64 amount_dec = (Int64)Math.Round((amount - (double)(amount_int)) * 100);
  2331. if (amount_dec == 0)
  2332. {
  2333. return FirstLetterToUpperCase(ConvertEnglish(amount_int));
  2334. }
  2335. else
  2336. {
  2337. return FirstLetterToUpperCase(ConvertEnglish(amount_int)) + " Point " + ConvertEnglish(amount_dec);
  2338. }
  2339. }
  2340. catch (Exception e)
  2341. {
  2342. // TODO: handle exception
  2343. }
  2344. return "";
  2345. }
  2346. public static String ConvertEnglish(Int64 i)
  2347. {
  2348. if (i < 20)
  2349. {
  2350. return unitsNormal[i];
  2351. }
  2352. if (i < 100)
  2353. {
  2354. return tensNormal[i / 10] + ((i % 10 > 0) ? " " + ConvertEnglish(i % 10) : "");
  2355. }
  2356. if (i < 1000)
  2357. {
  2358. return unitsNormal[i / 100] + " hundred"
  2359. + ((i % 100 > 0) ? " and " + ConvertEnglish(i % 100) : "");
  2360. }
  2361. if (i < 100000)
  2362. {
  2363. return ConvertEnglish(i / 1000) + " thousand "
  2364. + ((i % 1000 > 0) ? " " + ConvertEnglish(i % 1000) : "");
  2365. }
  2366. if (i < 10000000)
  2367. {
  2368. return ConvertEnglish(i / 100000) + " lakh "
  2369. + ((i % 100000 > 0) ? " " + ConvertEnglish(i % 100000) : "");
  2370. }
  2371. if (i < 1000000000)
  2372. {
  2373. return ConvertEnglish(i / 10000000) + " crore "
  2374. + ((i % 10000000 > 0) ? " " + ConvertEnglish(i % 10000000) : "");
  2375. }
  2376. return ConvertEnglish(i / 1000000000) + " arab "
  2377. + ((i % 1000000000 > 0) ? " " + ConvertEnglish(i % 1000000000) : "");
  2378. }
  2379. public static List<String> StringSeprate(String input, int numCharacter)
  2380. {
  2381. string[] words = input.Split(' ');
  2382. int counter = 0;
  2383. int countWord = 0;
  2384. String result = "";
  2385. String result2 = "";
  2386. for (int i = 0; i < words.Length; i++)
  2387. {
  2388. int nextCounter = counter + words[i].Length;
  2389. if (nextCounter < numCharacter)
  2390. {
  2391. countWord++;
  2392. if (counter == 0)
  2393. result += words[i];
  2394. else
  2395. result += (" " + words[i]);
  2396. }
  2397. counter = nextCounter;
  2398. }
  2399. for (int i = countWord; i < words.Length; i++)
  2400. {
  2401. if (i == countWord)
  2402. result2 += words[i];
  2403. else
  2404. result2 += (" " + words[i]);
  2405. }
  2406. List<String> res = new List<string>();
  2407. res.Add(result);
  2408. res.Add(result2);
  2409. return res;
  2410. }
  2411. public static string FirstLetterToUpperCase(string s)
  2412. {
  2413. if (string.IsNullOrEmpty(s))
  2414. throw new ArgumentException("There is no first letter");
  2415. char[] a = s.ToCharArray();
  2416. a[0] = char.ToUpper(a[0]);
  2417. return new string(a);
  2418. }
  2419. public static void SaveDocFile(String inputFileName)
  2420. {
  2421. //Open an existing WordDocument
  2422. FileStream inputStream = new FileStream(inputFileName, FileMode.Open);
  2423. WordDocument document = new WordDocument(inputStream, FormatType.Docx);
  2424. //To-Do some manipulation
  2425. //To-Do some manipulation
  2426. //Saving the Word document
  2427. FileStream outputStream = new FileStream("Sample.docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite);
  2428. document.Save(outputStream, FormatType.Docx);
  2429. document.Close();
  2430. outputStream.Flush();
  2431. outputStream.Dispose();
  2432. }
  2433. private static void IterateTextBody(WTextBody textBody)
  2434. {
  2435. //Iterates through each of the child items of WTextBody
  2436. for (int i = 0; i < textBody.ChildEntities.Count; i++)
  2437. {
  2438. //IEntity is the basic unit in DocIO DOM.
  2439. //Accesses the body items (should be either paragraph, table or block content control) as IEntity
  2440. IEntity bodyItemEntity = textBody.ChildEntities[i];
  2441. //A Text body has 3 types of elements - Paragraph, Table and Block Content Control
  2442. //Decides the element type by using EntityType
  2443. switch (bodyItemEntity.EntityType)
  2444. {
  2445. case EntityType.Paragraph:
  2446. WParagraph paragraph = bodyItemEntity as WParagraph;
  2447. //Checks for particular style name and removes the paragraph from DOM
  2448. if (paragraph.StyleName == "MyStyle")
  2449. {
  2450. int index = textBody.ChildEntities.IndexOf(paragraph);
  2451. textBody.ChildEntities.RemoveAt(index);
  2452. }
  2453. break;
  2454. case EntityType.Table:
  2455. //Table is a collection of rows and cells
  2456. //Iterates through table's DOM
  2457. IterateTable(bodyItemEntity as WTable);
  2458. break;
  2459. case EntityType.BlockContentControl:
  2460. BlockContentControl blockContentControl = bodyItemEntity as BlockContentControl;
  2461. //Iterates to the body items of Block Content Control.
  2462. IterateTextBody(blockContentControl.TextBody);
  2463. break;
  2464. }
  2465. }
  2466. }
  2467. public static string GetExcelColumnName(int columnNumber)
  2468. {
  2469. int dividend = columnNumber;
  2470. string columnName = String.Empty;
  2471. int modulo;
  2472. while (dividend > 0)
  2473. {
  2474. modulo = (dividend - 1) % 26;
  2475. columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
  2476. dividend = (int)((dividend - modulo) / 26);
  2477. }
  2478. return columnName;
  2479. }
  2480. private static void IterateTable(WTable table)
  2481. {
  2482. //Iterates the row collection in a table
  2483. foreach (WTableRow row in table.Rows)
  2484. {
  2485. //Iterates the cell collection in a table row
  2486. foreach (WTableCell cell in row.Cells)
  2487. {
  2488. //Table cell is derived from (also a) TextBody
  2489. //Reusing the code meant for iterating TextBody
  2490. IterateTextBody(cell);
  2491. }
  2492. }
  2493. }
  2494. public static bool CheckFile(String path)
  2495. {
  2496. return File.Exists(path);
  2497. }
  2498. public static void DeleteFile(String path)
  2499. {
  2500. File.Delete(path);
  2501. }
  2502. public static Byte[] GetFileByte(String path)
  2503. {
  2504. var dataBytes = File.ReadAllBytes(path);
  2505. return dataBytes;
  2506. }
  2507. public static Dictionary<String, String> GetAttribute(String data)
  2508. {
  2509. Dictionary<String, String> attributes = new Dictionary<String, String>();
  2510. string[] seprateSpace = data.Split(" ");
  2511. for (int i = 0; i < seprateSpace.Length; i++)
  2512. {
  2513. string[] seprateEqual = seprateSpace[i].Split("=\"");
  2514. if (seprateEqual.Length >= 2)
  2515. {
  2516. if (seprateEqual[0] == "\"__VIEWSTATEGENERATOR\"")
  2517. {
  2518. attributes.Add(seprateEqual[0], seprateEqual[1].Remove(seprateEqual[1].Length - 1, 1));
  2519. }
  2520. else
  2521. {
  2522. Regex regex = new Regex("value=(['\"])(?:\\/.+?)\\1", RegexOptions.IgnoreCase);
  2523. Match match;
  2524. string value = seprateEqual[1];
  2525. for (match = regex.Match(seprateSpace[i]); match.Success; match = match.NextMatch())
  2526. {
  2527. string d = match.Groups[0].Value.Substring(7);
  2528. value = d.Remove(d.Length - 1, 1);
  2529. }
  2530. attributes.Add(seprateEqual[0], value);
  2531. }
  2532. }
  2533. }
  2534. return attributes;
  2535. }
  2536. public static List<KeyValuePair<string, string>> ParseDataRequest(String responseText)
  2537. {
  2538. List<KeyValuePair<string, string>> data;
  2539. data = new List<KeyValuePair<string, string>>();
  2540. Regex regex = new Regex("<input.*?(?:name=\"*\".*?value=\"([^\"]+)| value =\"([^\"]+).*? name =\"*\")\"[^>]*>", RegexOptions.IgnoreCase);
  2541. Match match;
  2542. for (match = regex.Match(responseText); match.Success; match = match.NextMatch())
  2543. {
  2544. Dictionary<String, String> attrs = UtilsController.GetAttribute(match.Groups[0].Value);
  2545. String key = "";
  2546. String value = "";
  2547. foreach (KeyValuePair<string, string> item in attrs)
  2548. {
  2549. if (item.Key == "name")
  2550. {
  2551. key = item.Value;
  2552. }
  2553. if (item.Key == "value")
  2554. {
  2555. value = item.Value;
  2556. }
  2557. }
  2558. if (!key.Contains("cmdTraCuu") && !key.Contains("__EVENTTARGET") && !key.Contains("__EVENTARGUMENT"))
  2559. {
  2560. string resultKey = Regex.Replace(key, @"[^\w\d]", "");
  2561. data.Add(new KeyValuePair<string, string>(resultKey, value));
  2562. }
  2563. }
  2564. return data;
  2565. }
  2566. }
  2567. }