How to Write Sql Query to show total number of leaveDays per months after calculating date difference between startDate and endDate - postgresql

There is Leave Table.It has two columns start-date,end-date.I need to show total Number of Leave Days Per Month. At first I have to calculate totalNumberOfLeave just like:
<table>
<tr>
<th>Person</th>
<th>startDate</th>
<th>endDate</th>
<th>totalNumberOfLeave</th>
</tr>
<tr>
<td>PersonA</td>
<td>2016-08-10</td>
<td>2016-08-12</td>
<td>3</td>
</tr>
<tr>
<td>PersonB</td>
<td>2016-08-31</td>
<td>2016-09-03</td>
<td>4</td>
</tr>
<tr>
<td>PersonC</td>
<td>2016-08-30</td>
<td>2016-09-06</td>
<td>9</td>
</tr>
</table>
After calculating TotalNumberOfLeave,Then I need to show totalNumberOfLeave Per Month just like
<table>
<tr>
<th>Month</th>
<th>NumberOfLeave</th>
</tr>
<tr>
<td>8</td>
<td>6</td>
</tr>
</table>
(Person A takes 2016-08-10,2016-08-11,2016-08-12 as Leave,Person B takes 2016-08-31 as Leave,PersonC takes 2016-08-30,2016-08-31 as Leave in August)
How should I write for showing totalNumberOfLeave Per Month?
DB I use is Postgresql9.3.

SELECT
DATE_PART('MONTH',A.ATTENDANCEDATE) AS MONTH,
SUM(CASE WHEN (A.FULLDAY = '1') THEN 1 ELSE 0.5 END ) AS DURATION
FROM
(
SELECT GENERATE_SERIES(START_DATE,END_DATE, '1 DAY'::INTERVAL) AS ATTENDANCEDATE, IS_FULLDAY AS FULLDAY
FROM LEAVE_TAKEN
) AS A
GROUP BY
DATE_PART('MONTH',A.ATTENDANCEDATE)
ORDER BY
DATE_PART('MONTH',A.ATTENDANCEDATE);

Related

AIML Parser Example

I need some help to understand AIML templates using an example below, your help is appreciated to get this template working.
These are some of the sample inputs I am trying to handle and output I want to generate from AIML parsing.
Input : sale abc
Output : SALES ABC
Input : sales abc
Output : SALES ABC
Input : sale of product abc
Output : SALES ABC
Input : sale product abc
Output : SALES ABC
Input : What is the sale of product abc
Output : SALES ABC
Input : What is the average sale of product abc
Output : AVG SALES ABC
Input : What is the avg sale of product abc
Output : AVG SALES ABC
Input : What is the last 30 day average sale of product abc
Output : AVG SALES ABC 30
Input : What is the last 30 day avg sale of product abc
Output : AVG SALES ABC 30
I have been trying to start with something like this to begin with but this does not seem to progress well due to lack of clarity on this tool to me.
<category><pattern>
# <set>numbers</set> <set>days</set> <set>average</set> sales <set>prepositions</set> *</pattern>
<template>SALES <star index="1"/>,<star index="2"/>,<star index="3"/>,<star index="4"/>,<star index="5"/>,<star index="6"/> </template>
</category>
Where numbers set define > 1,2,3,4,5..... 100
Days set define > day, days
Average set define > average, avg , averages
Prepositions set define > of
Thanks!
You should do this with wildcards rather than sets. The only sets you need are for your products and possibly a set for the number of days.
This category is the response to your first 4 queries:
<category>
<pattern>SALE <set>products</set></pattern>
<template>
SALES <star/>
</template>
</category>
We can now use wildcards to <srai> to call the master category:
<category>
<pattern>SALES ^ <set>products</set> ^</pattern>
<template>
<srai>SALE <star index="2"/></srai>
</template>
</category>
<category>
<pattern>SALE ^ <set>products</set> ^</pattern>
<template>
<srai>SALE <star index="2"/></srai>
</template>
</category>
<category>
<pattern>WHAT IS THE SALE ^ <set>products</set> ^</pattern>
<template>
<srai>SALE <star index="2"/></srai>
</template>
</category>
This category handles your next 2 queries:
<category>
<pattern>WHAT IS ^ AVERAGE SALE ^ <set>products</set> ^</pattern>
<template>
AVG SALES <star index="3"/>
</template>
</category>
We can use this to say that AVG means AVERAGE. You could also put this in your normal.substitutions file.
<category>
<pattern>_ AVG *</pattern>
<template>
<srai><star/> average <star index="2"/></srai>
</template>
</category>
Finally, this category handles your last 2 queries.
<category>
<pattern>WHAT IS ^ LAST * DAY ^ AVERAGE SALE ^ <set>products</set> ^</pattern>
<template>
AVG SALES <star index="5"/> <star index="2"/>
</template>
</category>

format month of grouped news items in Typo3

I have news items, grouped by year and month. Here the code:
<f:groupedFor each="{paginatedNews}" as="groupedNews1" groupBy="yearOfDatetime" groupKey="year">
<f:groupedFor each="{groupedNews1}" as="groupedNews" groupBy="monthOfDatetime" groupKey="month">
<div style="border:1px solid blue;padding:10px;margin:10px;">
<h1>{month} {year} </h1>
<f:for each="{groupedNews}" as="newsItem">
<f:render partial="List/Item" arguments="{newsItem: newsItem,settings:settings,iterator:iterator}" />
</f:for>
</div>
</f:groupedFor>
</f:groupedFor>
Unfortunately, month and year are displayed in numbers in frontend, e.g.
03 2019
..(some news items)
02 2019
...
01 2019
However, what I need is this:
March 2019
...
February 2019
...
January 2019
How can I achieve this?
On the original EXT:news this method has been used:
Look at the template EXT:news/Resources/Private/Templates/News/DateMenu.html
<f:translate key="month.{month}" />
on the EXT:news/Resources/Private/Language/locallang.xlf you will find:
<trans-unit id="month.01" xml:space="preserve">
<source>January</source>
</trans-unit>
And so forth.

Paypal - billing cycle length?

Nothing is more confusing to me than PayPal documentation..
Basically I am trying to set a recurring payment. Each month pay 400.50 Euro for 'Membership' Of course the button they provided failed, but I found some examples and came up with:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="example#example.com">
<input type="hidden" name="return" value="http://www.example.com">
<input type="hidden" name="cancel_return" value="http://www.example.com">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="item_name" value="Membership" />
<input type="hidden" name="src" value="1"> <!-- recurring=yes -->
<input type="hidden" name="sra" value="1"> <!-- reattempt=yes -->
<input type="hidden" name="p3" value="1"> <!-- billing cycle length -->
<input type="hidden" name="a3" value="400.50" />
<input type="hidden" name="t3" value="M">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribe_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
What value should"billing cycle length" be - now default 1?
Does this mean once the user clicks my button - a payment will be extracted every month or it will only work one time (that 1 value)?
According to this PayPal documentation p3 is the subscription duration and should be used in conjunction with the value of t3.
Here's the details from that page:
p3 - Required
Subscription duration. Specify an integer value in the allowable range for the units of duration that you specify with t3.
t3 - Required
Regular subscription units of duration.
Allowable values are:
D — for days; allowable range for p3 is 1 to 90
W — for weeks; allowable range for p3 is 1 to 52
M — for months; allowable range for p3 is 1 to 24
Y — for years; allowable range for p3 is 1 to 5
So the current configuration is a recurring payment for only 1 Month.
I hope that this helps!
Use "srt" with some values greater then 1
<input type="hidden" name="src" value="1" />
<input type="hidden" name="srt" value="12" /><!--- 12 Month, paypal allowedonly 12 Month i think--->

Watir,click on a date from a date picker 62 days from current date

I need to click on a date that is 62 days later than the current date.
The next button for the months is clickable so I have been able to move the calendar to 2 months later but unable to select the date.
Eg if the current date is 4 July then I need to select 6th Sept.
My code at the moment looks somewhat like this.
b.element(:name, "policyperiod_endDate").click <-- datetime picker's click
b.element(:xpath, "(//button[#type='button'])[50]").click <-- next month
b.element(:xpath, "(//button[#type='button'])[50]").click
b.element(:link,"06").click <--doesnt select 08
b.element(:xpath, "(//button[#type='button'])[68]").click <-selects fixed cell n
how to select 06?
The outer HTML is like this:
input type="text" class="pull-left pdr35 ng-isolate-scope ng-pristine ng- invalid ng-invalid-required" datepicker-popup="yyyy-MM-dd" is-open="datePickerOpts.datepickers.policyperiod_startdate[1]" ng-model="policyIVOs.policyEndDate" name="**policyperiod_endDate**" datepicker-options="dateOptions" show-button-bar="false" close-on-date-selection="true" show-weeks="false" ng-click="open($event, 'policyperiod_startdate', 1)" min-date="policyEndMin" max-date="policyEndMax" required="" readonly=""

How Do I Calculate Date Difference in Javascript

i want to count the date difference (days only) like if i am selecting "Date From" as 08-05-2016 and then "Date To" as 08-11-2016 ... it will calculate the days difference as "7" before submitting in leave count box the values on run time Using Javascript
Below is the text values codes.
Date From: <input type="date" name="from">
Date To: <input type="date" name="to">
Leave Count: <input type="text" name="leavecount">
<input type="submit" name="submit">